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

WIP: Update spacy and train new models #22

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion data/meta_medium.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
"author":"Daniel Hoadley and Mark Neumann",
"email": "[email protected]",
"url":"https://github.com/ICLRandD/Blackstone",
"license":"Apache 2.0"
"license":"Apache 2.0",
"version": "0.5.0",
"spacy_version": ">=2.3.0,<3.0.0"
}
4 changes: 3 additions & 1 deletion data/meta_small.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
"author":"Daniel Hoadley and Mark Neumann",
"email": "[email protected]",
"url":"https://github.com/ICLRandD/Blackstone",
"license":"Apache 2.0"
"license":"Apache 2.0",
"version": "0.5.0",
"spacy_version": ">=2.3.0,<3.0.0"
}
199 changes: 0 additions & 199 deletions scripts/init_model.py

This file was deleted.

31 changes: 31 additions & 0 deletions scripts/release_medium.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

set -e
VERSION=${1}

# Notes
# Important to install spacy-lookups-data before running this script, as otherwise
# models don't have lemmatization and normalization data.
# TODO:
# - add version not from metadata files
# - try out pretraining with raw text
# - clean up release models after the fact
# - explicitly clone the EWT repo

mkdir -p release

spacy init-model en ./release/base_medium --freqs-loc ./for_mark/word_freqs.txt -v ./word2vec.txt

# Parser, starting from base model
spacy train en ./release/parser_tagger_medium ../UD_English-EWT/en_ewt-ud-train.json ../UD_English-EWT/en_ewt-ud-dev.json -G --pipeline tagger,parser --n-iter 10 --base-model ./release/base_medium
# NER, starting from best parsing model
spacy train en ./release/ner_medium ./train.json ./dev.json -G --pipeline ner --n-iter 10 --base-model ./release/parser_tagger_medium/model-best

# Package
spacy package release/ner_medium/model-best release/ -m ./data/meta_medium.json

# Pop down in to directory, build package, copy it back up and return.
current=${pwd}
cd release/en_core_law_md-${VERSION}
python setup.py sdist
cp dist/* ../
cd ${current}
31 changes: 31 additions & 0 deletions scripts/release_small.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

set -e
VERSION=${1}

# Notes
# Important to install spacy-lookups-data before running this script, as otherwise
# models don't have lemmatization and normalization data.
# TODO:
# - add version not from metadata files
# - try out pretraining with raw text
# - clean up release models after the fact
# - explicitly clone the EWT repo

mkdir -p release

spacy init-model en ./release/base_small --freqs-loc ./for_mark/word_freqs.txt

# Parser, starting from base model
spacy train en ./release/parser_tagger_small ../UD_English-EWT/en_ewt-ud-train.json ../UD_English-EWT/en_ewt-ud-dev.json -G --pipeline tagger,parser --n-iter 10 --base-model ./release/base_small
# NER, starting from best parsing model
spacy train en ./release/ner_small ./train.json ./dev.json -G --pipeline ner --n-iter 10 --base-model ./release/parser_tagger_small/model-best

# Package
spacy package release/ner_small/model-best release/ -m ./data/meta_small.json

# Pop down in to directory, build package, copy it back up and return.
current=${pwd}
cd release/en_core_law_sm-${VERSION}
python setup.py sdist
cp dist* ../
cd ${current}
2 changes: 1 addition & 1 deletion scripts/train_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def compute_vectors(input_path: Path, output_path: Path):
sentences = LineSentence(input_path)
bigram_transformer = Phrases(sentences)
model = Word2Vec(
bigram_transformer[sentences], size=150, window=5, min_count=5, workers=4
bigram_transformer[sentences], size=100, window=5, min_count=5, workers=4
)
print(f"Saving vectors to {output_path}")
model.wv.save_word2vec_format(output_path, binary=False)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
packages=find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]),
license="Apache",
install_requires=[
"spacy==2.1.8",
"spacy>=2.3.0,<3.0.0",
"requests", # required for the legislation linker.
"conllu",
"numpy",
Expand Down