-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75561b6
commit fb4dade
Showing
9 changed files
with
217 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,3 +116,4 @@ Makefile | |
|
||
# eval | ||
UD/ | ||
training/**/data |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Instructions to run the evaluation | ||
---------------------------------- | ||
|
||
The scores are calculated on `Universal Dependencies <https://universaldependencies.org/>`_ treebanks on single word tokens (including some contractions but not merged prepositions). They can be reproduced by the following steps: | ||
|
||
1. Update ``DATA_URL`` in ``download-eval-data.py`` to point to the latest treebanks archive from `Universal Dependencies <https://universaldependencies.org/#download>` (or the version that you which to use). | ||
2. Run ``python3 download-eval-data.py`` which will | ||
1. Download the archive | ||
2. Extract relevant data (language and if applicable specific treebank, see notes in the results table) | ||
3. Concatenate the train, dev and test data into a single file (e.g. ``cat de_gsd*.conllu > de-gsd-all.conllu``) | ||
4. Store the files at the expected location (``data/UD/``) | ||
5. Install the evaluation dependencies (``pip install -r eval-requirements.txt``) | ||
6. Run the script, e.g. from the home directory ``python3 evaluate_simplema.py`` | ||
7. Results are stored at ``data/results/results_summary.csv``. Also, errors are written in a CSV file for each dataset under the ``data/results``folder. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from typing import Iterable, List, Tuple | ||
from os import mkdir, path, scandir | ||
import re | ||
import logging | ||
import tarfile | ||
import requests | ||
from glob import glob | ||
|
||
from simplemma.strategies.dictionaries.dictionary_factory import SUPPORTED_LANGUAGES | ||
|
||
log = logging.getLogger(__name__) | ||
logging.basicConfig(level=logging.INFO) | ||
DATA_URL = "https://lindat.mff.cuni.cz/repository/xmlui/bitstream/handle/11234/1-5150/ud-treebanks-v2.12.tgz?sequence=1&isAllowed=y" | ||
DATA_FOLDER = path.join(path.dirname(__file__), "..", "data") | ||
DATA_FILE = path.join(DATA_FOLDER, "ud-treeebanks.tgz") | ||
CLEAN_DATA_FOLDER = path.join(DATA_FOLDER, "UD") | ||
|
||
def get_dirs(file_name: str) -> List[str]: | ||
return [dir.name for dir in scandir(file_name) if dir.is_dir()] | ||
|
||
def get_files(file_name: str) -> List[str]: | ||
return [dir.name for dir in scandir(file_name) if dir.is_file()] | ||
|
||
def get_relevant_language_data_folders(data_folder) -> Iterable[Tuple[str, str, str]]: | ||
for lang_folder in get_dirs(data_folder): | ||
lang_data_folder = path.join(uncompressed_data_folder, lang_folder) | ||
conllu_file = glob(path.join(lang_data_folder, "*.conllu"))[0] | ||
dataset_name = re.search("^.*/(.*)-ud.*$", conllu_file).groups()[0] | ||
lang = dataset_name.split("_")[0] | ||
|
||
if lang in SUPPORTED_LANGUAGES: | ||
yield (lang, dataset_name, lang_data_folder) | ||
|
||
if path.exists(DATA_FOLDER) or path.exists(CLEAN_DATA_FOLDER): | ||
raise Exception("Data folder seems to be already present. Delete it before creating new data.") | ||
|
||
mkdir(DATA_FOLDER) | ||
mkdir(CLEAN_DATA_FOLDER) | ||
|
||
log.info("Downloading evaluation data...") | ||
response = requests.get(DATA_URL) | ||
open(DATA_FILE, "wb").write(response.content) | ||
|
||
log.info("Uncompressing evaluation data...") | ||
tarfile.open(DATA_FILE).extractall(DATA_FOLDER).close() | ||
uncompressed_data_folder = path.join(DATA_FOLDER, glob(f"{DATA_FOLDER}/ud-treebanks-*")[0]) | ||
|
||
log.info("Filtering files...") | ||
for (lang, dataset_name, dataset__folder) in get_relevant_language_data_folders(uncompressed_data_folder): | ||
log.info(lang + " - " + dataset__folder) | ||
# Concatenate the train, dev and test data into a single file (e.g. ``cat de_gsd*.conllu > de-gsd-all.conllu``) | ||
lang_clean_data_file = path.join(CLEAN_DATA_FOLDER, f"{dataset_name}.conllu") | ||
log.debug(f"Procressing data for {dataset_name}") | ||
with open(lang_clean_data_file, 'w') as outfile: | ||
for file in glob(path.join(dataset__folder, "*.conllu")): | ||
with open(file) as infile: | ||
for line in infile: | ||
outfile.write(line) |
File renamed without changes.
Oops, something went wrong.