Update misc.py
Browse files
misc.py
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import transformers
|
| 3 |
+
|
| 4 |
+
class ContextualModelConfig(transformers.configuration_utils.PretrainedConfig):
|
| 5 |
+
"""We create a dummy configuration class that will just set properties
|
| 6 |
+
based on whatever kwargs we pass in.
|
| 7 |
+
|
| 8 |
+
When this class is initialized (see experiments.py) we pass in the
|
| 9 |
+
union of all data, model, and training args, all of which should
|
| 10 |
+
get saved to the config json.
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
def __init__(self, **kwargs):
|
| 14 |
+
for key, value in kwargs.items():
|
| 15 |
+
try:
|
| 16 |
+
json.dumps(value)
|
| 17 |
+
setattr(self, key, value)
|
| 18 |
+
except TypeError:
|
| 19 |
+
# value was not JSON-serializable, skip
|
| 20 |
+
continue
|
| 21 |
+
super().__init__()
|