Views
No views yet
1git clone https://github.com/zouharvi/pwesuite.git
2cd pwesuite
3mkdir -p computed/models
4pip3 install -e .
5
6# download the three models
7wget https://huggingface.co/zouharvi/PWESuite-metric_learner/resolve/main/rnn_metric_learning_token_ort_all.pt -O computed/models/
8wget https://huggingface.co/zouharvi/PWESuite-metric_learner/resolve/main/rnn_metric_learning_token_ipa_all.pt -O computed/models/
9wget https://huggingface.co/zouharvi/PWESuite-metric_learner/resolve/main/rnn_metric_learning_panphon_all.pt -O computed/models/1from models.metric_learning.model import RNNMetricLearner
2from models.metric_learning.preprocessor import preprocess_dataset_foreign
3from main.utils import load_multi_data
4import torch
5import tqdm
6import math
7
8data = load_multi_data(purpose_key="all")
9data = preprocess_dataset_foreign(
10 [
11 {"token_ort": "Hello", "token_ipa": None},
12 {"token_ort": "what", "token_ipa": None},
13 {"token_ort": "is", "token_ipa": None},
14 {"token_ort": "pwesuite", "token_ipa": None},
15 ],
16 features="token_ort"
17)
18
19model = RNNMetricLearner(
20 dimension=300,
21 feature_size=data[0][0].shape[1],
22)
23model.load_state_dict(torch.load("computed/models/rnn_metric_learning_token_ort_all.pt"))
24
25# some cheap paralelization
26BATCH_SIZE = 32
27data_out = []
28for i in tqdm.tqdm(range(math.ceil(len(data) / BATCH_SIZE))):
29 batch = [f for f, _ in data[i * BATCH_SIZE:(i + 1) * BATCH_SIZE]]
30 data_out += list(
31 model.forward(batch).detach().cpu().numpy()
32 )
33
34assert len(data) == len(data_out)
35assert all([len(x) == 300 for x in data_out])1mkdir -p computed/embd/
2python3 ./models/metric_learning/apply.py -l all -mp computed/models/rnn_metric_learning_token_ipa_all.pt -o computed/embd/rnn_metric_learning_token_ipa_all.pkl --features token_ipa
3python3 ./suite_evaluation/eval_all.py --embd computed/embd/rnn_metric_learning_token_ipa_all.pklhuman_similarity: 0.6054
correlation: 0.8995
retrieval: 0.9158
analogy: 0.1128
rhyme: 0.6375
cognate: 0.6513
JSON1!{"human_similarity": 0.6053864496119294, "correlation": 0.8995336394813026, "retrieval": 0.9157905555555556, "analogy": 0.1127777777777778, "rhyme": 0.6374601910828025, "cognate": 0.6512651265126512, "overall": 0.6370356233370033}
Score (overall): 0.6370@inproceedings{zouhar-etal-2024-pwesuite,
title = "{PWES}uite: Phonetic Word Embeddings and Tasks They Facilitate",
author = "Zouhar, Vil{\'e}m and
Chang, Kalvin and
Cui, Chenxuan and
Carlson, Nate B. and
Robinson, Nathaniel Romney and
Sachan, Mrinmaya and
Mortensen, David R.",
booktitle = "Proceedings of the 2024 Joint International Conference on Computational Linguistics, Language Resources and Evaluation (LREC-COLING 2024)",
month = may,
year = "2024",
address = "Torino, Italia",
publisher = "ELRA and ICCL",
url = "https://aclanthology.org/2024.lrec-main.1168/",
pages = "13344--13355",
}