Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0 #128

Merged
merged 457 commits into from
Aug 27, 2021
Merged

3.0 #128

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
457 commits
Select commit Hold shift + click to select a range
df75c58
Update 2.0
dumitrescustefan Dec 22, 2020
b27591d
Partial update
dumitrescustefan Dec 23, 2020
994c743
Bugfix
tiberiu44 Dec 31, 2020
f201ad7
API update
dumitrescustefan Jan 6, 2021
e97107d
Bugfixing and API
tiberiu44 Jan 7, 2021
734e24e
Bugfix
tiberiu44 Jan 7, 2021
2ea260e
Fix long words OOM by skipping sentences
dumitrescustefan Jan 7, 2021
55b7be2
Merge branch '2.0' of https://github.com/adobe/NLP-Cube into 2.0
dumitrescustefan Jan 7, 2021
e7143f0
bugfixing and api update
tiberiu44 Jan 7, 2021
c64991a
Merge branch '2.0' of https://github.com/adobe/NLP-Cube into 2.0
tiberiu44 Jan 7, 2021
6209f12
Added language flavour
tiberiu44 Jan 7, 2021
7c0b2c0
Added early stopping condition
tiberiu44 Jan 7, 2021
37040ac
Corrected naming
tiberiu44 Jan 7, 2021
9e2156d
Corrected permissions
tiberiu44 Jan 7, 2021
c600029
Bugfix
tiberiu44 Jan 8, 2021
c2a3649
Added GPU support at runtime
tiberiu44 Jan 8, 2021
07243ae
Wrong config package
tiberiu44 Jan 8, 2021
7980d96
Refactoring
tiberiu44 Jan 8, 2021
61c5b3a
refactoring
tiberiu44 Jan 8, 2021
efdef5b
add lightning to dependencies
tiberiu44 Jan 8, 2021
8d9ed74
Dummy test
tiberiu44 Jan 8, 2021
2d68eda
Dummy test
tiberiu44 Jan 8, 2021
e595d51
Tweak
tiberiu44 Jan 8, 2021
e6c839f
Tweak
tiberiu44 Jan 8, 2021
f2df03e
Update test
tiberiu44 Jan 8, 2021
5476e0b
Test
tiberiu44 Jan 8, 2021
483f1f9
Finished loading for UD CONLL-U format
tiberiu44 Jan 8, 2021
0cb76de
Working on tagger
tiberiu44 Jan 9, 2021
72cdcfb
Work on tagger
tiberiu44 Jan 9, 2021
3987217
tagger training
tiberiu44 Jan 9, 2021
96a0e96
tagger training
tiberiu44 Jan 9, 2021
1dee270
tagger training
tiberiu44 Jan 9, 2021
6b8c8f6
Sync
tiberiu44 Jan 10, 2021
08e5d8f
Sync
tiberiu44 Jan 10, 2021
c7a2684
Sync
tiberiu44 Jan 10, 2021
47c76a7
Sync
tiberiu44 Jan 10, 2021
daf9d6b
Tagger working
tiberiu44 Jan 10, 2021
0e857f1
Better weight for aux loss
tiberiu44 Jan 10, 2021
25547a2
Better weight for aux loss
tiberiu44 Jan 11, 2021
cac1484
Added save and printing for tagger and shared options class
dumitrescustefan Jan 11, 2021
aa435b0
Multilanguage evaluation
tiberiu44 Jan 13, 2021
6f3598f
Saving multiple models
dumitrescustefan Jan 13, 2021
33531e2
Updated ignore list
tiberiu44 Jan 13, 2021
293e368
Merge branch '3.0' of https://github.com/adobe/NLP-Cube into 3.0
tiberiu44 Jan 13, 2021
78b1f1e
Added XLM-Roberta support
tiberiu44 Jan 13, 2021
09a7717
Using custom ro model
tiberiu44 Jan 13, 2021
ba42dff
Score update
dumitrescustefan Jan 13, 2021
e80575c
Bugfixing
tiberiu44 Jan 14, 2021
58ae614
Code refactor
tiberiu44 Jan 14, 2021
ad57f3b
Refactor
tiberiu44 Jan 14, 2021
31d8476
Added option to load external config
tiberiu44 Jan 14, 2021
c891dce
Added option to select LM-model from CLI or config
tiberiu44 Jan 14, 2021
73cd151
added option to overwrite config lm from CLI
tiberiu44 Jan 14, 2021
96ea7fb
Bugfix
tiberiu44 Jan 14, 2021
638b99f
Working on parser
tiberiu44 Jan 14, 2021
5bdab7c
Sync work on parser
tiberiu44 Jan 15, 2021
96c6b78
Parser working
tiberiu44 Jan 15, 2021
974f510
Removed load limit
tiberiu44 Jan 15, 2021
8b78026
Bugfix in evaluation
tiberiu44 Jan 15, 2021
9ca836b
Added bi-affine attention
tiberiu44 Jan 15, 2021
b89382d
Added experimental ChuLiuEdmonds tree decoding
tiberiu44 Jan 16, 2021
b9b3f66
Better config for parser and bugfix
tiberiu44 Jan 16, 2021
1d35d40
Added residuals to tagging
tiberiu44 Jan 16, 2021
7145b02
Model update
tiberiu44 Jan 17, 2021
d3b24da
Switched to AdamW optimizer
tiberiu44 Jan 18, 2021
499d3d3
Working on tokenizer
tiberiu44 Jan 18, 2021
64f5b4c
Working on tokenizer
tiberiu44 Jan 18, 2021
7bdf518
Training working - validation to do
tiberiu44 Jan 18, 2021
5b3fad5
Bugfix in language id
tiberiu44 Jan 18, 2021
d258ab3
Working on tokenization validation
tiberiu44 Jan 19, 2021
5b0601c
Tokenizer working
tiberiu44 Jan 19, 2021
888cf4f
YAML update
dumitrescustefan Jan 19, 2021
a8bc130
Merge branch '3.0' of https://github.com/adobe/NLP-Cube into 3.0
dumitrescustefan Jan 19, 2021
b178643
Bug in LMHelper
dumitrescustefan Jan 19, 2021
6e40594
Tagger is working
dumitrescustefan Jan 19, 2021
582f330
Tokenizer is working
tiberiu44 Jan 19, 2021
7c124ef
Merge branch '3.0' of https://github.com/adobe/NLP-Cube into 3.0
tiberiu44 Jan 19, 2021
da267af
bfix
tiberiu44 Jan 19, 2021
82c3442
bfix
tiberiu44 Jan 19, 2021
954c68a
Bugfix for bugfix :)
tiberiu44 Jan 19, 2021
4286610
Sync
tiberiu44 Jan 19, 2021
c0c01ca
Tokenizer worker
tiberiu44 Jan 20, 2021
dcc7a6b
Tagger working
dumitrescustefan Jan 24, 2021
4060387
Trainer updates
dumitrescustefan Jan 24, 2021
44b126d
Trainer process now working
dumitrescustefan Jan 26, 2021
dba40ce
Added .DS_Store
rscctest Jan 27, 2021
5211ea9
Added datasets for Compound Word Expander and Lemmatizer
rscctest Jan 27, 2021
d974ff1
Added collate function for lemma+compound
rscctest Jan 27, 2021
80487ca
Added training and validation step
rscctest Jan 27, 2021
c53bc2e
Updated config for Lemmatizer
rscctest Jan 28, 2021
a2d8345
Minor fixes
rscctest Jan 28, 2021
479e6fb
Removed duplicate entries from lemma and cwe
rscctest Jan 28, 2021
7e766ef
Added training support for lemmatizer
rscctest Jan 28, 2021
fe41cb0
Removed debug directives
rscctest Jan 28, 2021
f87f920
Lemmatizer in testing phase
rscctest Jan 28, 2021
39799e2
removed unused line
rscctest Jan 28, 2021
25387ae
Bugfix in Lemma dataset
rscctest Jan 28, 2021
11734e8
Corrected validation issue with gs labels being sent to the forward m…
rscctest Jan 28, 2021
d27571c
Lemmatizier training done
rscctest Jan 28, 2021
f4b3f29
Compound word expander ready
rscctest Jan 28, 2021
0868000
Sync
rscctest Jan 28, 2021
6befc0f
Added support for FastText, Transformers and Languasito LM models
rscctest Jan 29, 2021
c95fb5d
Added multi-lm support for tokenizer
rscctest Jan 29, 2021
6bd843e
Added support for multiword tokens
rscctest Jan 29, 2021
04569a5
Sync
rscctest Jan 29, 2021
57778ac
Bugfix in evaluation
rscctest Jan 29, 2021
c367702
Added Languasito as a subpackage
rscctest Jan 29, 2021
2c83d74
Added path to local Languasito
rscctest Jan 29, 2021
094c268
Bugfixing all around
rscctest Jan 29, 2021
08ff6b1
Removed debug printing
rscctest Jan 29, 2021
f534ecb
Bugfix for no-space languages that actually contain spaces :)
rscctest Jan 29, 2021
e27f3bd
Bugfix for no-space languages that actually contain spaces :)
rscctest Jan 29, 2021
ac69ef9
Fixed GPU support
tiberiu44 Jan 30, 2021
1f8cbd7
Biaffine transform for LAS and relative head location (RHL) for UAS
tiberiu44 Jan 31, 2021
cbfd546
Bugfix
tiberiu44 Jan 31, 2021
a8f4714
Tweaks
tiberiu44 Jan 31, 2021
85e16d0
moved rhl to lower layer
tiberiu44 Jan 31, 2021
be89087
Added configurable option for RHL
tiberiu44 Feb 1, 2021
dac1fb7
Safenet for spaces in languages that should use no spaces
rscctest Feb 1, 2021
2b64dc5
Better defaults
tiberiu44 Feb 1, 2021
8999afc
Merge branch '3.0' of https://github.com/adobe/NLP-Cube into 3.0
tiberiu44 Feb 1, 2021
e3ca3ea
Sync
tiberiu44 Feb 2, 2021
4ceb712
Cleanup parser
tiberiu44 Feb 2, 2021
d8998c9
Bilinear xpos and attrs
rscctest Feb 2, 2021
9c63fe1
Added Biaffine module from Stanza
rscctest Feb 2, 2021
25ba112
Tagger with reduced number of parameters:
rscctest Feb 2, 2021
c65306c
Parser with conditional attrs
rscctest Feb 2, 2021
39c79c4
Working on tokenizer runtime
rscctest Feb 2, 2021
9c4a4aa
Tokenizer process 90% done
tiberiu44 Feb 2, 2021
1764995
Added runtime for parser, tokenizer and tagger
tiberiu44 Feb 2, 2021
a9fa45d
Added quick test for runtime
tiberiu44 Feb 2, 2021
2acbfdc
Test for e2e
tiberiu44 Feb 3, 2021
d69da61
Merge
tiberiu44 Feb 4, 2021
a93d852
Added support for multiple word embeddings at the same time
Feb 4, 2021
896d2f4
Merge branch '3.0' of https://github.com/adobe/NLP-Cube into 3.0
Feb 4, 2021
bf03444
Bugfix
Feb 4, 2021
7c93955
Added multiple word representations for tokenizer
rscctest Feb 5, 2021
8405b6c
moved mask_concat to utils.py
rscctest Feb 5, 2021
216eb19
Added XPOS prediction to pipeline
tiberiu44 Feb 6, 2021
32884c7
Bugfix in tokenizer shifted word embeddings
tiberiu44 Feb 6, 2021
23f9660
Using Languasito tokenizer for HF tokenization
tiberiu44 Feb 6, 2021
895e9c8
Bugfix
tiberiu44 Feb 7, 2021
d89962d
Bugfixing
tiberiu44 Feb 7, 2021
525d04d
Merge branch '3.0' of https://github.com/adobe/NLP-Cube into 3.0
tiberiu44 Feb 7, 2021
b66d26d
Bugfixing
tiberiu44 Feb 7, 2021
88e34ed
Bugfix
tiberiu44 Feb 7, 2021
25c7fb2
Runtime fixing
tiberiu44 Feb 7, 2021
45c2c21
Sync
rscctest Feb 8, 2021
6f612df
Added spa for FT and Languasito
tiberiu44 Feb 8, 2021
ecb1367
Added spa for FT and Languasito
tiberiu44 Feb 8, 2021
37152ca
Minor tweaks
tiberiu44 Feb 8, 2021
5aaa22c
Added configuration for RNN layers
tiberiu44 Feb 8, 2021
7d91756
Bugfix for spa
rscctest Feb 9, 2021
7dbefc1
HF runtime fix
tiberiu44 Feb 9, 2021
fec6a2d
Mixed test fasttext+transformer
tiberiu44 Feb 10, 2021
3b187a2
Added word reconstruction and MHA
rscctest Feb 11, 2021
5a86b25
Sync
rscctest Feb 11, 2021
205852c
Bugfix
rscctest Feb 11, 2021
5a3e9ed
bugfix
rscctest Feb 11, 2021
b20309f
Added masked attention
rscctest Feb 11, 2021
04f1d66
Sync
tiberiu44 Feb 12, 2021
e582eaa
Added test for runtime
tiberiu44 Feb 12, 2021
3a23314
Bugfix in mask values
tiberiu44 Feb 12, 2021
e5a7391
Updated test
tiberiu44 Feb 12, 2021
969ac73
Added full mask dropout
tiberiu44 Feb 13, 2021
e5a0212
Added resume option
tiberiu44 Feb 13, 2021
a5356f4
Removed useless printouts
tiberiu44 Feb 13, 2021
e1706bc
Removed useless printouts
tiberiu44 Feb 13, 2021
87038c1
Switched to eval at runtime
tiberiu44 Feb 14, 2021
8961f8e
multiprocessing added
dumitrescustefan Feb 14, 2021
033bf88
Added full mask dropout for word decoder
tiberiu44 Feb 15, 2021
673dec5
Bugfix
tiberiu44 Feb 15, 2021
e3e33de
Residual
tiberiu44 Feb 16, 2021
c5f9c16
Added lexical-contextual cosine loss
tiberiu44 Feb 16, 2021
cf23762
Removed full mask dropout from WordDecoder
tiberiu44 Feb 16, 2021
74bde22
Bugfix
tiberiu44 Feb 16, 2021
b4697d9
Training script generation update
dumitrescustefan Feb 18, 2021
6a4f93b
Added residual
tiberiu44 Feb 22, 2021
7363e78
Updated languasito to pickle tokenized lines
dumitrescustefan Feb 22, 2021
139a3bb
Updated languasito to pickle tokenized lines
dumitrescustefan Feb 22, 2021
fe7e087
Updated languasito to pickle tokenized lines
dumitrescustefan Feb 22, 2021
c95d60d
Not training for seq len > max_seq_len
rscctest Feb 22, 2021
197b213
Added seq limmits for collates
rscctest Feb 22, 2021
685555d
Passing seq limits from collate to tokenizer
rscctest Feb 22, 2021
023b67a
Skipping complex parsing
rscctest Feb 22, 2021
96c0eca
Working on word decomposer
rscctest Feb 24, 2021
93b1717
Model update
tiberiu44 Feb 25, 2021
3396702
Sync
tiberiu44 Feb 25, 2021
f0ce55e
Bugfix
tiberiu44 Feb 25, 2021
d621e7e
Bugfix
tiberiu44 Feb 25, 2021
ec154da
Bugfix
tiberiu44 Feb 25, 2021
a8e090a
Using all reprs
tiberiu44 Mar 2, 2021
3176356
Dropped immediate context
tiberiu44 Mar 5, 2021
17cf390
Multi train script added
dumitrescustefan Mar 6, 2021
f9f5e12
Changed gpu parameter type to string, for multiple gpus int failed
dumitrescustefan Mar 11, 2021
affd46c
Updated pytorch_lightning callback method to work with newer version
dumitrescustefan Mar 13, 2021
9fc2ed5
Updated pytorch_lightning callback method to work with newer version
dumitrescustefan Mar 13, 2021
a0bd6a9
Transparently pass PL args from the command line; skip over empty com…
dumitrescustefan Mar 13, 2021
4d67bb3
Fix typo
dumitrescustefan Mar 22, 2021
775a949
Refactoring and on the way to working API
dumitrescustefan Apr 2, 2021
879a965
API load working
dumitrescustefan Apr 3, 2021
c988509
Partial _call_ working
dumitrescustefan Apr 3, 2021
76ca34f
Partial _call_ working
dumitrescustefan Apr 3, 2021
9829a36
Added partly working api and refactored everything back to cube/. Com…
dumitrescustefan May 8, 2021
32b20d6
api is working
rscctest Aug 5, 2021
17fdca6
Fixing api
rscctest Aug 5, 2021
bec1b1c
Updated readme
rscctest Aug 5, 2021
5669a9e
Update Readme to include flavours
rscctest Aug 5, 2021
03ad480
Device support
rscctest Aug 5, 2021
c11888e
api update
rscctest Aug 5, 2021
eecbb3b
Updated package
rscctest Aug 5, 2021
e1e9b0b
Tweak + results
rscctest Aug 5, 2021
51f5ed2
Clarification
rscctest Aug 5, 2021
8a373f6
Test update
rscctest Aug 8, 2021
fb21a67
Update
rscctest Aug 8, 2021
00b8a66
Sync
rscctest Aug 9, 2021
9cc59d8
Update README
rscctest Aug 9, 2021
e08ce39
Bugfixing
rscctest Aug 9, 2021
e4c365a
Bugfix and api update
rscctest Aug 9, 2021
2507c82
Fixed compound
rscctest Aug 9, 2021
fb7069e
Evaluation update
rscctest Aug 9, 2021
9f72f66
Bugfix
tiberiu44 Aug 9, 2021
2a948fc
Merge branch '3.0' of https://github.com/adobe/NLP-Cube into 3.0
tiberiu44 Aug 9, 2021
deb8110
Package update
tiberiu44 Aug 9, 2021
a93176c
Bugfix for large sentences
rscctest Aug 11, 2021
a3bbc83
Pip package update
rscctest Aug 11, 2021
fa1c60f
Corrected spanish evaluation
rscctest Aug 11, 2021
b29fc89
Package version update
rscctest Aug 11, 2021
9aadd75
Fixed tokenization issues on transformers
rscctest Aug 11, 2021
d6e7c3e
Removed pinned memory
tiberiu44 Aug 11, 2021
e60526e
Bugfix for GPU tensors
tiberiu44 Aug 11, 2021
b82b380
Update package version
tiberiu44 Aug 11, 2021
b7c241a
Automatically detecting hidden state size
tiberiu44 Aug 12, 2021
909327e
Automatically detecting hidden state size
tiberiu44 Aug 12, 2021
9d75f67
Automatically detecting hidden state size
tiberiu44 Aug 12, 2021
cc49b1b
Sync
tiberiu44 Aug 12, 2021
8e000c2
Evaluation update
tiberiu44 Aug 12, 2021
5d48ddd
Package update
tiberiu44 Aug 12, 2021
b61bc16
Bugfix
rscctest Aug 13, 2021
9569e32
Bugfixing
tiberiu44 Aug 15, 2021
d95c8a5
Package version update
tiberiu44 Aug 15, 2021
4933255
Merge branch '3.0' of github.com:adobe/NLP-Cube into 3.0
tiberiu44 Aug 15, 2021
454366d
Bugfix
tiberiu44 Aug 15, 2021
65c1d09
Package version update
tiberiu44 Aug 15, 2021
8ab611e
Update evaluation for Italian
tiberiu44 Aug 15, 2021
b561d7f
tentative support torchtext>=0.9.0 (#127)
KoichiYasuoka Aug 15, 2021
5254d3b
Update package dependencies
tiberiu44 Aug 15, 2021
b799812
Merge branch '3.0' of github.com:adobe/NLP-Cube into 3.0
tiberiu44 Aug 15, 2021
4f2b854
RC
tiberiu44 Aug 15, 2021
0717fe4
Merge branch 'master' into 3.0
tiberiu44 Aug 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
68 changes: 13 additions & 55 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,19 @@
version: 2
version: 2.1

orbs:
python: circleci/python@0.2.1

jobs:
test_api_and_main_and_upload:
docker:
- image: circleci/python
build-and-test:
executor: python/default
steps:
- checkout
- run:
name: init .pypirc
command: |
echo -e "[pypi]" >> ~/.pypirc
- run:
name: install requirements
command: |
sudo apt-get install -y libblas3 liblapack3
sudo apt-get install -y liblapack-dev libblas-dev
cd /home/circleci/project/
pip3 install --user -r requirements.txt
- run:
name: test main
command: |
cd /home/circleci/project/
python3 tests/main_tests.py
- run:
name: test api
command: |
cd /home/circleci/project/
python3 tests/api_tests.py
- run:
name: create packages
command: |
python3 setup.py sdist
python3 setup.py bdist_wheel
- run:
name: upload to pypi
command: |
if [[ "$PYPI_USERNAME" == "" ]]; then
echo "Skip upload"
exit 0
fi
python3 -m pip install --user jq
if [[ "$CIRCLE_BRANCH" == "master" ]]; then
PYPI="pypi.org"
else
PYPI="test.pypi.org"
fi
LATEST_VERSION="$(curl -s https://$PYPI/pypi/nlpcube/json | jq -r '.info.version')"
THIS_VERSION=`python3 <<< "import pkg_resources;print(pkg_resources.require('nlpcube')[0].version)"`
if [[ $THIS_VERSION != $LATEST_VERSION ]]; then
echo "\n\nthis: $THIS_VERSION - latest: $LATEST_VERSION => releasing to $PYPI\n\n"
python3 -m pip install --user --upgrade twine
python3 -m twine upload --repository-url https://$PYPI/legacy/ dist/* -u $PYPI_USERNAME -p $PYPI_PASSWORD || echo "Package already exists"
else
echo "this: $THIS_VERSION = latest: $LATEST_VERSION => skip release"
fi
- python/load-cache
- python/install-deps
- python/save-cache
- run: echo "done"

workflows:
version: 2
test_api_and_main_and_upload:
main:
jobs:
- test_api_and_main_and_upload
- build-and-test
16 changes: 15 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
.DS_Store
Languasito/data/
*.txt
lightning_logs
*.gz
*.encodings
*.npy
data/*
nlp-cube-models/*
corpus/
models/
scripts/packer
*.pyc
build/
dist/
Expand All @@ -11,12 +23,14 @@ cube/venv/*
.idea/*
venv/*
cube/*.py
*.json

models/
scratch/
tests/scratch/*
scripts/*.json
scripts/*.conllu
scripts/*.md
scripts/wikiextractor.py

# Jupyter notebooks
notebooks/.ipynb_checkpoints/*
Expand Down
8 changes: 8 additions & 0 deletions Languasito/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions cube/.idea/cube.iml → Languasito/.idea/Languasito.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions Languasito/.idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Languasito/.idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cube/.idea/misc.xml → Languasito/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cube/.idea/modules.xml → Languasito/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Languasito/.idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
63 changes: 63 additions & 0 deletions Languasito/languasito/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import sys
import torch
from typing import *

sys.path.append('')

from languasito.model import Languasito
from languasito.utils import LanguasitoCollate
from languasito.utils import Encodings


class LanguasitoAPI:

def __init__(self, languasito: Languasito, encodings: Encodings):
self._languasito = languasito
self._languasito.eval()
self._encodings = encodings
self._collate = LanguasitoCollate(encodings, live=True)
self._device = 'cpu'

def to(self, device: str):
self._languasito.to(device)
self._device = device

def __call__(self, batch):
with torch.no_grad():
x = self._collate.collate_fn(batch)
for key in x:
if isinstance(x[key], torch.Tensor):
x[key] = x[key].to(self._device)
rez = self._languasito(x)
emb = []
pred_emb = rez['emb'].detach().cpu().numpy()
for ii in range(len(batch)):
c_emb = []
for jj in range(len(batch[ii])):
c_emb.append(pred_emb[ii, jj])
emb.append(c_emb)
return emb

@staticmethod
def load(model_name: str):
from pathlib import Path
home = str(Path.home())
filename = '{0}/.languasito/{1}'.format(home, model_name)
import os
if os.path.exists(filename + '.encodings'):
return LanguasitoAPI.load_local(filename)
else:
print("UserWarning: Model not found and automatic downloading is not yet supported")
return None

@staticmethod
def load_local(model_name: str):
enc = Encodings()
enc.load('{0}.encodings'.format(model_name))
model = Languasito(enc)
tmp = torch.load('{0}.best'.format(model_name), map_location='cpu')
# model.load(tmp['state_dict'])
model.load_state_dict(tmp['state_dict'])
model.eval()
api = LanguasitoAPI(model, enc)
return api
Loading