internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: keras-team/keras-nlp

Issue:
Add compilation defaults for the MaskedLM task models
In https://github.com/keras-team/keras-nlp/issues/709 we added compilation defaults to all classification tasks. We should also do the same for all `XXMaskedLM` models. E.g. [bert](https://github.com/keras-team/keras-nlp/blob/master/keras_nlp/models/bert/bert_masked_lm.py). Here's the full list of models.

- [ ] `AlbertMaskedLM`
- [ ] `BertMaskedLM`
- [ ] `DebertV3MaskedLM`
- [ ] `DistilBertMaskedLM`
- [ ] `FNetMaskedLM`
- [ ] `RobertaMaskedLM`

https://github.com/keras-team/keras-nlp/pull/714 is a good template PR. We can probably just use Adam and `1e-5` or `2e-5` as a learning rate for now. Though a little experimentation for each model to make sure the task does converge would be helpful. This [colab](https://gist.github.com/mattdangerw/b16c257973762a0b4ab9a34f6a932cc1) may be a helpful starting place.


Discussion:
I am new here to contribute open source and looking for issues. Can I try this issue, I have programming knowledge on python.
/assign
Hi @mattdangerw , I can take this up !
@mattdangerw How about this ... @Ujjal99kumar seems a beginner, but this issue is not good first issue. We can let him have crack at `BertMaskedLM` while I will raise PRs for rest of models ! I can review his pr as peer review, helping him.
@mattdangerw I will like to contribute in this issue.
@Ujjal99kumar @shivance we can split up models and raise PR.
Sounds good @Cyber-Machine ! Let's split up, let @Ujjal99kumar try `BertMaskedLM` , and you can take `DebertaMaskedLM` and `FNetMaskedLM` !
Thanks !

Resolving patch:
diff --git a/keras_nlp/models/f_net/f_net_masked_lm.py b/keras_nlp/models/f_net/f_net_masked_lm.py
--- a/keras_nlp/models/f_net/f_net_masked_lm.py
+++ b/keras_nlp/models/f_net/f_net_masked_lm.py
@@ -24,6 +24,7 @@
 )
 from keras_nlp.models.f_net.f_net_presets import backbone_presets
 from keras_nlp.models.task import Task
+from keras_nlp.utils.keras_utils import is_xla_compatible
 from keras_nlp.utils.python_utils import classproperty
 
 
@@ -135,6 +136,12 @@ def __init__(
         # All references to `self` below this line
         self.backbone = backbone
         self.preprocessor = preprocessor
+        self.compile(
+            loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
+            optimizer=keras.optimizers.Adam(5e-5),
+            weighted_metrics=keras.metrics.SparseCategoricalAccuracy(),
+            jit_compile=is_xla_compatible(self),
+        )
 
     @classproperty
     def backbone_cls(cls):


Test patch:
diff --git a/keras_nlp/models/f_net/f_net_masked_lm_test.py b/keras_nlp/models/f_net/f_net_masked_lm_test.py
--- a/keras_nlp/models/f_net/f_net_masked_lm_test.py
+++ b/keras_nlp/models/f_net/f_net_masked_lm_test.py
@@ -87,6 +87,9 @@ def setUp(self):
     def test_valid_call_masked_lm(self):
         self.masked_lm(self.preprocessed_batch)
 
+    def test_fnet_masked_lm_fit_default_compile(self):
+        self.masked_lm.fit(self.raw_dataset)
+
     @parameterized.named_parameters(
         ("jit_compile_false", False), ("jit_compile_true", True)
     )
Repository: keras-team/keras-nlp

Issue:
Add a temperature argument to the Contrastive Sampler 
Similar to our other samplers, we should add the temperature argument to the `Contrastive Sampler` along with the necessary tests.
The approach for accomplishing the same can be seen in #951. 

I would like to take this up. Thanks!



Discussion:
Thanks! Please do.

Resolving patch:
diff --git a/keras_nlp/samplers/contrastive_sampler.py b/keras_nlp/samplers/contrastive_sampler.py
--- a/keras_nlp/samplers/contrastive_sampler.py
+++ b/keras_nlp/samplers/contrastive_sampler.py
@@ -76,8 +76,9 @@ def __init__(
         k=5,
         alpha=0.6,
         seed=None,
+        **kwargs,
     ):
-        super().__init__()
+        super().__init__(**kwargs)
         self.k = k
         self.alpha = alpha
         self.seed = seed
@@ -133,7 +134,7 @@ def cond(prompt, cache, index, logits, hidden_states):
 
         def body(prompt, cache, index, logits, hidden_states):
             # Compute the softmax distribution for the next token.
-            probabilities = keras.activations.softmax(logits)
+            probabilities = keras.activations.softmax(logits / self.temperature)
 
             # Replicate for `self.k` times to find the best token in top-k
             # candidates.


Test patch:
diff --git a/keras_nlp/samplers/contrastive_sampler_test.py b/keras_nlp/samplers/contrastive_sampler_test.py
--- a/keras_nlp/samplers/contrastive_sampler_test.py
+++ b/keras_nlp/samplers/contrastive_sampler_test.py
@@ -11,7 +11,7 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-"""Tests for Top-K sampler."""
+"""Tests for Contrastive Sampler."""
 
 import tensorflow as tf
 from absl.testing import parameterized
@@ -45,7 +45,7 @@ def next(prompt, cache, index):
             return logits, hidden_states, cache
 
         self.next = next
-        self.sampler = ContrastiveSampler(k=5, alpha=0.2)
+        self.sampler = ContrastiveSampler(k=5, alpha=0.2, temperature=1.0)
 
     def join_as_string(self, x):
         return ["".join([self.int_lookup[i] for i in s]) for s in x.numpy()]
Repository: keras-team/keras-nlp

Issue:
AutoGraph error upon model.fit() in GPT 
**Describe the bug**

<details><summary>StackTrace</summary>
<p>

OperatorNotAllowedInGraphError            Traceback (most recent call last)
[<ipython-input-10-6ef525f3a2b6>](https://localhost:8080/#) in <cell line: 1>()
----> 1 model.fit(train_ds, validation_data=val_ds, verbose=2, epochs=EPOCHS)

1 frames
[/usr/local/lib/python3.10/dist-packages/keras_core/src/utils/traceback_utils.py](https://localhost:8080/#) in error_handler(*args, **kwargs)
    121             # To get the full stack trace, call:
    122             # `keras_core.config.disable_traceback_filtering()`
--> 123             raise e.with_traceback(filtered_tb) from None
    124         finally:
    125             del filtered_tb

[/usr/local/lib/python3.10/dist-packages/keras_nlp/src/metrics/perplexity.py](https://localhost:8080/#) in result(self)
    161 
    162     def result(self):
--> 163         if self._number_of_samples == 0:
    164             return 0.0
    165         perplexity_score = ops.exp(

OperatorNotAllowedInGraphError: Using a symbolic `tf.Tensor` as a Python `bool` is not allowed: AutoGraph is disabled in this function. Try decorating it directly with @tf.function.

</p>
</details> 

**To Reproduce**
[Colab Notebook](https://colab.research.google.com/drive/1779-TFbLUbVapOl8BQS1aLJF2LlLT2ZS?usp=sharing)



**Would you like to help us fix it?**
Yes


Discussion:

Resolving patch:
diff --git a/keras_nlp/metrics/perplexity.py b/keras_nlp/metrics/perplexity.py
--- a/keras_nlp/metrics/perplexity.py
+++ b/keras_nlp/metrics/perplexity.py
@@ -160,10 +160,10 @@ def update_state(self, y_true, y_pred, sample_weight=None):
         self._number_of_samples.assign_add(batch_size)
 
     def result(self):
-        if self._number_of_samples == 0:
-            return 0.0
-        perplexity_score = ops.exp(
-            self._aggregate_crossentropy / self._number_of_samples
+        perplexity_score = ops.where(
+            ops.equal(self._number_of_samples, 0),
+            0,
+            ops.exp(self._aggregate_crossentropy / self._number_of_samples),
         )
         return perplexity_score
 


Test patch:
Repository: weecology/retriever

Issue:
Retriever doesn't fail gracefully if trying to list datasets without running update
If the GUI or `retriever update` have never been run and `retriever ls` is run from the command line the following results:

```
ethan@natasha:~$ retriever ls
Available datasets (0):
Traceback (most recent call last):
File "/usr/local/bin/retriever", line 9, in <module>
load_entry_point('retriever==1.5', 'console_scripts', 'retriever')()
  File "/usr/local/lib/python2.7/dist-packages/retriever-1.5-py2.7.egg/retriever/__main__.py", line 92, in main
    lscolumns.printls(sorted(list(all_scripts), key=lambda s: s.lower()))
  File "/usr/local/lib/python2.7/dist-packages/retriever-1.5-py2.7.egg/retriever/lscolumns.py", line 33, in printls
    for pos in range(len(columns[0])):
UnboundLocalError: local variable 'columns' referenced before assignment
```

Instead it should report back to the user something like:

```
ethan@natasha:~$ retriever ls
No datasets are currently available. Try running:
retriever update
```



Discussion:

Resolving patch:
diff --git a/__main__.py b/__main__.py
--- a/__main__.py
+++ b/__main__.py
@@ -84,6 +84,13 @@ def main():
         if args.command == 'ls' or args.dataset is None:
             import lscolumns
 
+            #If scripts have never been downloaded there is nothing to list
+            if not script_list:
+                print "No scripts are currently available. Updating scripts now..."
+                check_for_updates(graphical=False)
+                print "\n\nScripts downloaded.\n"
+                script_list = SCRIPT_LIST()
+
             all_scripts = set([script.shortname for script in script_list])
             all_tags = set(["ALL"] + 
                             [tag.strip().upper() for script in script_list for tagset in script.tags for tag in tagset.split('>')])


Test patch:
Repository: weecology/retriever

Issue:
Choose button missing on Database Connection page for Windows & OS X
When selecting a database connection that has an associated file (i.e., sqlite and Access) the GUI should allow you to navigate to the file by clicking on the `Choose` button. This works fine on Ubuntu:

![screenshot from 2014-01-21 17 01 53](https://f.cloud.github.com/assets/744427/1968743/aa25e82a-82e7-11e3-9762-577c0a8009e5.png)

But this button is missing on the current builds on Windows and OS X. The Database Connection page also generally looks narrower on Windows and OS X.

From Windows:
![win_dbconnect](https://f.cloud.github.com/assets/744427/1968800/c2414480-82e8-11e3-8ce4-524940122130.PNG)



Discussion:
@bendmorris any thoughts on this one. I'm doing some reading up on wx, but it's going to take me a while to get comfortable enough to solve this so I thought I'd see if you could point me in the right direction.


Resolving patch:
diff --git a/app/connect_wizard.py b/app/connect_wizard.py
--- a/app/connect_wizard.py
+++ b/app/connect_wizard.py
@@ -95,6 +95,14 @@ def __init__(self, parent, title, label):
         else:
             self.dblist.SetSelection(0)
         self.sizer.Add(self.dblist, -1, wx.EXPAND)
+
+        #TODO: This is a hack to force the wizard to be large enough to not hide
+        #the Choose button on the Connect Page when the engine has a file
+        #attribute. This should be fixed properly by figuring out how to make wx
+        #work with the fact that the connect page has varying fields depending
+        #on the engine.
+        longspace = StaticText(self, -1, "", wx.Size(375, -1))
+        self.sizer.Add(longspace, -1)
         
     def dirbtn_click(self, evt):
         dialog = wx.DirDialog(None, message="Choose a directory to " +
@@ -147,14 +155,8 @@ def Draw(self, evt):
                     self.fieldset[opt[0]] = wx.BoxSizer(wx.HORIZONTAL)
                     label = StaticText(self, -1, opt[0] + ": ", 
                                           size=wx.Size(90,35))
-                    if opt[0] == "password":
-                        txt = TextCtrl(self, -1, 
-                                          str(default), 
-                                          size=wx.Size(200,-1), 
-                                          style=wx.TE_PASSWORD)
-                    else:
-                        txt = TextCtrl(self, -1, str(default),
-                                          size=wx.Size(200,-1))
+                    style = wx.TE_PASSWORD if opt[0] == "password" else 0
+                    txt = TextCtrl(self, -1, str(default), size=wx.Size(200,-1), style=style)
                     self.option[opt[0]] = txt
                     self.fieldset[opt[0]].AddMany([label, 
                                                    self.option[opt[0]]])


Test patch:
Repository: weecology/retriever

Issue:
Final page of connection wizard reports nothing on Mac & Windows
The final page of the connection wizard is blank on both Mac & Windows. This happens regardless of success or failure and predates the recent changes to the GUI in #157.



Discussion:

Resolving patch:
diff --git a/app/connect_wizard.py b/app/connect_wizard.py
--- a/app/connect_wizard.py
+++ b/app/connect_wizard.py
@@ -184,15 +184,11 @@ class ConfirmPage(TitledPage):
     """The final confirmation page."""
     def __init__(self, parent, title, label):
         TitledPage.__init__(self, parent, title, label)
-        self.fields = wx.BoxSizer(wx.VERTICAL)
         self.parent = parent
         
     def Draw(self, evt):
         if not evt.GetDirection(): return
         
-        self.fields.Clear(True)
-        self.fields = wx.BoxSizer(wx.VERTICAL)
-        
         self.values_dict = dict()
         connect = self.parent.CONNECTION
         for key in connect.option.keys():
@@ -201,12 +197,12 @@ def Draw(self, evt):
         try:
             connect.engine.opts = self.values_dict
             connect.engine.connect(force_reconnect=True)
-            message = '''<p><b>Success!</b>Your connection has been saved.</p>
+            message = '''<p><b>Success!</b> Your connection has been saved.</p>
             <p>Click Finish to continue.</p>'''
             save_connection(connect.engine.name, self.values_dict)
             
         except Exception as e:
-            message = message = '''<p><b>Error.</b>There was a problem with your
+            message = message = '''<p><b>Error.</b> There was a problem with your
             connection:</p><p>%s</p>
             <p>Click Back to try again, or Cancel.</p>''' % e
             
@@ -216,7 +212,5 @@ def Draw(self, evt):
         self.message = HtmlWindow(self)
         self.message.SetSize((450,400))
         self.message.SetHtml(message)
-        self.fields.Add(self.message, 1, wx.EXPAND)
-        self.sizer.Add(self.fields)
-        
+        self.sizer.Add(self.message, 1, wx.EXPAND)
         self.sizer.Layout()


Test patch:
Repository: weecology/retriever

Issue:
Add --reset option to remove hidden files
We cache data and scripts in ~/.retriever. This is great most of the time, but sometimes you want to get rid of those files. We should add a:

`retriever --reset`

option to automatically get rid of this directory.



Discussion:

Resolving patch:
diff --git a/__main__.py b/__main__.py
--- a/__main__.py
+++ b/__main__.py
@@ -10,12 +10,13 @@
 import os
 import platform
 import sys
+import shutil
 # sys removes the setdefaultencoding method at startup; reload to get it back
 reload(sys)
 if hasattr(sys, 'setdefaultencoding'):
     # set default encoding to latin-1 to avoid ascii encoding issues
     sys.setdefaultencoding('latin-1')
-from retriever import VERSION, MASTER, SCRIPT_LIST, sample_script
+from retriever import VERSION, MASTER, SCRIPT_LIST, sample_script, HOME_DIR
 from retriever.engines import engine_list
 from retriever.lib.repository import check_for_updates
 from retriever.lib.lists import Category, get_lists
@@ -80,7 +81,26 @@ def main():
             f.close()
             
             return
-        
+
+        elif args.command == 'reset':
+            warn_msg = """This will remove existing scripts, cached data, and
+information on database connections. Specifically it will remove
+the scripts and raw_data folders and the connections.config file
+in {}
+Do you want to proceed? (y/N)\n""".format(HOME_DIR)
+            confirm = raw_input(warn_msg)
+            while not (confirm.lower() in ['y', 'n', '']):
+                print("Please enter either y or n.")
+                confirm = raw_input(warn_msg)
+            if confirm.lower() == 'y':
+                shutil.rmtree(os.path.join(HOME_DIR, 'raw_data'))
+                shutil.rmtree(os.path.join(HOME_DIR, 'scripts'))
+                try:
+                    os.remove(os.path.join(HOME_DIR, 'connections.config'))
+                except:
+                    pass
+            return
+
         if args.command == 'ls' or args.dataset is None:
             import lscolumns
 
diff --git a/lib/get_opts.py b/lib/get_opts.py
--- a/lib/get_opts.py
+++ b/lib/get_opts.py
@@ -51,4 +51,6 @@
 citation_parser = subparsers.add_parser('citation', help='view citation')
 citation_parser.add_argument('dataset', help='dataset name', nargs='?', default=None)
 
-help_parser = subparsers.add_parser('help', help='')
\ No newline at end of file
+reset_parser = subparsers.add_parser('reset', help='reset retriever: removes configation settings, scripts, and cached data')
+
+help_parser = subparsers.add_parser('help', help='')


Test patch:
Repository: weecology/retriever

Issue:
Check if format_column_name can be safely removed
I only see two references to this function. In engine.py (lines 438-439) it simply passes back the column name:

```
def format_column_name(self, column):
    return column
```

In msaccess.py (lines 55-56) if adds hard brackets:

```
def format_column_name(self, column):
    return "[" + str(column) + "]"
```

I don't see any sign that either of these functions is actually called:

```
ethan@natasha:~/Dropbox/Informatics/Retriever/src (more-tests)$ grep -r format_column_name *
engines/msaccess.py:    def format_column_name(self, column):
lib/engine.py:    def format_column_name(self, column):
```

Should be tested on a Windows machine to be safe.



Discussion:

Resolving patch:
diff --git a/engines/msaccess.py b/engines/msaccess.py
--- a/engines/msaccess.py
+++ b/engines/msaccess.py
@@ -52,9 +52,6 @@ def drop_statement(self, objecttype, objectname):
     def escape_single_quotes(self, value):
         return value.replace("'", "''")
         
-    def format_column_name(self, column):
-        return "[" + str(column) + "]"
-        
     def insert_data_from_file(self, filename):
         """Perform a bulk insert."""
         self.get_cursor()
diff --git a/lib/engine.py b/lib/engine.py
--- a/lib/engine.py
+++ b/lib/engine.py
@@ -442,9 +442,6 @@ def final_cleanup(self):
             
         self.disconnect()
 
-    def format_column_name(self, column):
-        return column
-        
     def find_file(self, filename):
         for search_path in DATA_SEARCH_PATHS:
             search_path = search_path.replace("{dataset}", self.script.shortname)


Test patch:
Repository: weecology/retriever

Issue:
Existing scripts are not detected and so scripts are always redownloaded
The `if not file_exists` check in `lib/repository.py` is returning True even when scripts are present in `~/.retriever/scripts/`. This means that scripts are always downloaded whether they are present or not.

From a quick glance it appears this check is not searching through the `SCRIPT_SEARCH_PATHS` and is therefore not finding the scripts.



Discussion:

Resolving patch:
diff --git a/lib/repository.py b/lib/repository.py
--- a/lib/repository.py
+++ b/lib/repository.py
@@ -8,7 +8,7 @@
 from hashlib import md5
 from inspect import getsourcelines
 from threading import Thread
-from retriever import REPOSITORY, VERSION, MASTER_BRANCH, REPO_URL, SCRIPT_WRITE_PATH
+from retriever import REPOSITORY, VERSION, MASTER_BRANCH, REPO_URL, SCRIPT_WRITE_PATH, HOME_DIR
 from retriever.lib.models import file_exists
 
 global abort, executable_name
@@ -156,7 +156,7 @@ def run(self):
                 else:
                     script_version = None
 
-                if not file_exists(os.path.join("scripts", script_name)):
+                if not file_exists(os.path.join(HOME_DIR, "scripts", script_name)):
                     # File doesn't exist: download it
                     print "Downloading script: " + script_name
                     download_from_repository("scripts/" + script_name,


Test patch:
Repository: weecology/retriever

Issue:
Clean install from source leads to unwriteable .retriever directories
If you install the retriever from source and there are not an existing `~/.retriever/raw_data/` and `~/.retriever/scripts/` directories, these directories are created on install. Since the source install requires the use of `sudo` these directories are owned by `root` and when the retriever is run (typically using non-elevated privileges) it cannot write to those directories.

Removing the directories or changing their ownerships solves the problem, but this should be avoided.



Discussion:
Hi, I've install the Retriever and see this problem. I'm a little confused about why it is not appropriate to change the ownership of these directories to the user who installs the Retriever. 

Hi @lyttonhao - Sorry about that. You're right that the correct behavior is definitely to have the ownership of these directories be the user who does the install. The problem is that by default when installing as a super user ownership ends up getting set to `root`. This definitely needs to be fixed, we just haven't had time to do it yet.

Thank you for the response @ethanwhite. I will try to fix it by changing the ownerships in the code and see if it works.


Resolving patch:
diff --git a/__init__.py b/__init__.py
--- a/__init__.py
+++ b/__init__.py
@@ -12,6 +12,9 @@
 from lib.compile import compile_script
 import platform
 
+current_platform = platform.platform().lower()
+if not "win" in current_platform:
+    import pwd
 
 VERSION = 'v1.7.0'
 MASTER = True
@@ -27,6 +30,10 @@
     if not os.path.exists(dir):
         try:
             os.makedirs(dir)
+            if (not "win" in current_platform) and os.getenv("SUDO_USER"):
+                # change the ownership of dir directory to the user who is calling this sudo command 
+                pw = pwd.getpwnam( os.getenv("SUDO_USER") )
+                os.chown(dir, pw.pw_uid, pw.pw_gid)
         except OSError:
             print "The Retriever lacks permission to access the ~/.retriever/ directory."
             raise
@@ -46,7 +53,6 @@
 
 # create a default data directory for Windows since the Windows installer places
 # the executable in a place where users won't expect the data to be stored.
-current_platform = platform.platform().lower()
 user_desktop = os.path.join(os.path.expanduser('~'), 'Desktop')
 DATA_DIR = user_desktop if "win" in current_platform else '.'
 


Test patch: