flavienbwk
commited on
Commit
•
47f365d
1
Parent(s):
dad60c9
Added dummy model
Browse files- README.md +4 -0
- config.json +4 -0
- train.py +26 -0
README.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1 |
---
|
2 |
license: mit
|
3 |
---
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: mit
|
3 |
---
|
4 |
+
|
5 |
+
This is a dummy model outputting the count of "a" letters in a provided sentence.
|
6 |
+
|
7 |
+
To generate the dummy model, run `python3 train.py`
|
config.json
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"torch_dtype": "float32",
|
3 |
+
"transformers_version": "4.37.2"
|
4 |
+
}
|
train.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import PreTrainedModel, PretrainedConfig
|
2 |
+
|
3 |
+
class CountAModel(PreTrainedModel):
|
4 |
+
config_class = PretrainedConfig
|
5 |
+
|
6 |
+
def __init__(self, config):
|
7 |
+
super().__init__(config)
|
8 |
+
|
9 |
+
def forward(self, text):
|
10 |
+
return text.lower().count('a')
|
11 |
+
|
12 |
+
def save_pretrained(self, save_directory):
|
13 |
+
self.config.save_pretrained(save_directory)
|
14 |
+
|
15 |
+
config = PretrainedConfig()
|
16 |
+
config.torch_dtype = 'float32' # Add a dummy torch_dtype attribute
|
17 |
+
config.model_type = 'CountA'
|
18 |
+
model = CountAModel(config)
|
19 |
+
|
20 |
+
# Validate
|
21 |
+
sentence = "This is a sample sentence with a few 'a's."
|
22 |
+
count_a = model(sentence)
|
23 |
+
print(f"The sentence contains {count_a} letter(s) 'a'.")
|
24 |
+
|
25 |
+
# Save the model in the current directory
|
26 |
+
model.save_pretrained(".")
|