Spaces:
Running
Running
Commit
·
25a9cb9
1
Parent(s):
abed273
Add vocab file
Browse files- Nested/utils/data.py +1 -0
- Nested/utils/vocab.py +14 -0
Nested/utils/data.py
CHANGED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from Nested.utils.vocab import Vocab
|
Nested/utils/vocab.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class Vocab:
|
| 2 |
+
def _init_(self, counter, specials=[]) -> None:
|
| 3 |
+
self.itos = list(counter.keys()) + specials
|
| 4 |
+
self.stoi = {s: i for i, s in enumerate(self.itos)}
|
| 5 |
+
self.word_count = counter
|
| 6 |
+
|
| 7 |
+
def get_itos(self) -> list[str]:
|
| 8 |
+
return self.itos
|
| 9 |
+
|
| 10 |
+
def get_stoi(self) -> dict[str, int]:
|
| 11 |
+
return self.stoi
|
| 12 |
+
|
| 13 |
+
def _len_(self):
|
| 14 |
+
return len(self.itos)
|