All Projects → yuvalpinter → m3gm

yuvalpinter / m3gm

Licence: GPL-3.0 license
Max-Margin Markov Graph Models for WordNet (EMNLP 2018)

Programming Languages

python
139335 projects - #7 most used programming language
Jupyter Notebook
11667 projects
shell
77523 projects

Projects that are alternatives of or similar to m3gm

R-BERT
Pytorch re-implementation of R-BERT model
Stars: ✭ 59 (+47.5%)
Mutual labels:  relation-extraction
dialogre
Dialogue-Based Relation Extraction
Stars: ✭ 124 (+210%)
Mutual labels:  relation-extraction
textaugment
TextAugment: Text Augmentation Library
Stars: ✭ 280 (+600%)
Mutual labels:  wordnet
ws4j
WordNet Similarity for Java provides an API for several Semantic Relatedness/Similarity algorithms
Stars: ✭ 41 (+2.5%)
Mutual labels:  wordnet
CogNet
CogNet: a large-scale, high-quality cognate database for 338 languages, 1.07M words, and 8.1 million cognates
Stars: ✭ 26 (-35%)
Mutual labels:  wordnet
HNRE
Hierarchical Neural Relation Extraction
Stars: ✭ 93 (+132.5%)
Mutual labels:  relation-extraction
lambda-notebook
Lambda Notebook: Formal Semantics in Jupyter
Stars: ✭ 16 (-60%)
Mutual labels:  semantics
NatLang
NatLang is an English parser with an extensible grammar
Stars: ✭ 20 (-50%)
Mutual labels:  wordnet
DocuNet
Code and dataset for the IJCAI 2021 paper "Document-level Relation Extraction as Semantic Segmentation".
Stars: ✭ 84 (+110%)
Mutual labels:  relation-extraction
relation-extraction-rnn
Bi-directional LSTM model for relation extraction
Stars: ✭ 22 (-45%)
Mutual labels:  relation-extraction
oerschema
A RDF vocabulary for OER content on the web.
Stars: ✭ 21 (-47.5%)
Mutual labels:  semantics
copycat
Modern port of Melanie Mitchell's and Douglas Hofstadter's Copycat
Stars: ✭ 84 (+110%)
Mutual labels:  semantics
DISCOTRESS
🦜 DISCOTRESS 🦜 is a software package to simulate and analyse the dynamics on arbitrary Markov chains
Stars: ✭ 20 (-50%)
Mutual labels:  markov-model
envo
A community-driven ontology for the representation of environments
Stars: ✭ 106 (+165%)
Mutual labels:  semantics
CogIE
CogIE: An Information Extraction Toolkit for Bridging Text and CogNet. ACL 2021
Stars: ✭ 47 (+17.5%)
Mutual labels:  relation-extraction
accessible-name-automation-proof-of-concept
This is an experiment based on Accessibility Object Model (AOM). It tries to demonstrate that it is theoretically possible (in a certain way) to predict what the screen reader will say by focusing on semantic and non semantic elements with a bit of automated testing, thus reducing the need for manual testing.
Stars: ✭ 15 (-62.5%)
Mutual labels:  semantics
Ask2Transformers
A Framework for Textual Entailment based Zero Shot text classification
Stars: ✭ 102 (+155%)
Mutual labels:  relation-extraction
mchmm
Markov Chains and Hidden Markov Models in Python
Stars: ✭ 89 (+122.5%)
Mutual labels:  markov-model
semantic-python-overview
(subjective) overview of projects which are related both to python and semantic technologies (RDF, OWL, Reasoning, ...)
Stars: ✭ 406 (+915%)
Mutual labels:  semantics
Wordbook
Wordbook is a dictionary application built for GNOME.
Stars: ✭ 56 (+40%)
Mutual labels:  wordnet

PWC

M3GM

October 29: all model code is here, documented, and validated. Bonus content is here. All done!

This repository contains code for Max-Margin Markov Graph Models (M3GMs) as described in the paper: Predicting Semantic Relations using Global Graph Properties.

Full citation format below.

Code Requirements

The project was written and tested in Python 3.6. Some packages needed to run it include:

  • dynet 2.0
  • scipy
  • tqdm
  • nltk - with the wordnet corpus available

Write me, or open an issue, if you find more blocking dependencies!

Workflow

The eventual goal of training an M3GM model and replicating the results from the paper runs through a number of intermediate steps. Here is the hopefully full linearized flowchart, with some detailed descriptions in following sections:

  1. Create a pickled WordNet prediction dataset in sparse matrix format, using create_wn18_data.py. To use our exact dataset, obtain the distibution of WN18RR here and point the script at the text version.
  2. Obtain synset embeddings. These can be AutoExtend-based ones, which map directly to synsets, or any downloadable word embeddings which can then be averaged across synset lexemes, such as those from FastText.
  3. If your embeddings are word-level, synsetify them using embed_from_words.py. Run it without parameters to see usage.
  4. Train an association model (for baseline results or for training an M3GM on top) using pretrain_assoc.py. Demo command (for the result from the paper) given below.
  5. Train an M3GM using predict_wn18.py. Demo command (for results from the paper) given below.
  6. If so inclined, tune the alpha_r parameters using optimize_alpha_per_relation.py. You will need to do some math later to translate into results comparable to those in the paper.

Disclaimer: some of the code here takes a while to run. Any suggestions for improving any of the calculations, or for getting things to run on GPUs for that matter, will be most appreciated.

Association Models

This script trains a local association model using one of several models (see paper for details): Bilinear, TransE, Diag-R1 ("diagonal + rank-1 matrix"), DistMult. Be sure to keep record of the embedding dimension used (no need to provide the dimension as an argument if initializing from an a pre-trained file) and of the association algorithm (--assoc-mode), as these will be necessary for downstream M3GM training.

One parameter you may want to add depending on your target setup is --rule-override, which trains modules for all relations, including the four symmetric ones (in WordNet). It would also evaluate on trained modules in symmetric relations, rather than with a (high-accuracy) rule-based system. The default behavior, without this parameter, is training said modules once every five epochs, as it helps with synset embeddings tuning.

The --early-stopping method used is: for each dev epoch, if its MRR score is lower than both of the last two epochs, halt and return the best model so far.

Outputs

  • the auto-generated log file (avoid using --no-log) will output many, many scores and their components for every single instance encountered.
  • --model-out is readable both by this code for test mode, and by downstream M3GM trainer (--model param).

Demo command

python pretrain_assoc.py --input data/wn18rr.pkl --embeddings data/ft-embs-all-lower.vec --model-out models/pret_transE --nll --assoc-mode transE --neg-samp 10 --early-stopping --eval-dev

Max-Margin Markov Graph Models

The most powerful use case for M3GM is when we've trained a good association model, and augment it with weights for combinatorial graph features by way of M3GM training. It is best if the association weights, as well as the word embeddings, are frozen from this point on, using the --no-assoc-bp parameter. If we believe some of them to be bad, they can later be weighted down using the optimize_alpha_per_relation.py post-processor, which computes a best-performing association component weight for each relation. --model-only-init is a related parameter, which ensures that the M3GM component is trained over the data (makes more sense when considering that there's also an --ergm-model input parameter which can be used for picking up training from a saved point).

A prerequesite for this code to run in the common mode is that both --emb-size and assoc-mode are set to the same values that the association model was trained with.

Outputs

  • the auto-generated log file (avoid using --no-log) will output ERGM scores for all instances and negative samples in training phase, and all cases of re-ranking in the development data traversals.
  • --model-out will save the model in a four-file format that can later be read by both this script and the test-mode code (TODO).
  • --rerank-out provides an input file for optimize_alpha_per_relation.py. It includes all to-be-reranked lists from the dev set and scores from both association and graph components, as well as flags for the true instances.

Demo command

python predict_wn18.py --input data/wn18rr.pkl --emb-size 300 --model models/pret_transE-ep-14 --model-only-init --assoc-mode transE --eval-dev --no-assoc-bp --epochs 3 --neg-samp 10 --regularize 0.01 --rand-all --skip-symmetrics --model-out models/from_pret_trE-3eps --rerank-out from_pret_trE-3eps.txt

Model Development

A good entry point to try and play with the ERGM features underlying M3GM would be ergm_feats.py. Be sure to enter them into the cache and feature set in model.py so they can have weights trained for them.

Running the dataset creation code with the --no-symmetrics flag would result in a dataset we called WN18RSR when working on this research. It contains only the seven asymmetric, nonreciprocal relations. All model results on it are abysmal, but you're welcome to try :)

Repo-level TODOs

  • Add exploration Notebook for WordNet (WN) structure
  • Add mapping of Synset codes from WN 1.7.1 all the way to 3.0.
  • Move non-script code into lib directory
  • Remove dy.parameter() calls (deprecated in dynet 2.0.4)
  • Turn any remaining TODOs from here into repo issues

Citation

@InProceedings{pinter-eisenstein:2018:EMNLP,
  author    = {Pinter, Yuval  and  Eisenstein, Jacob},
  title     = {{Predicting Semantic Relations using Global Graph Properties}},
  booktitle = {Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing},
  month     = {October-November},
  year      = {2018},
  address   = {Brussels, Belgium},
  publisher = {Association for Computational Linguistics},
  pages     = {1741--1751},
  url       = {http://www.aclweb.org/anthology/D18-1201}
}

Contact

[email protected].

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].