Giter Club home page Giter Club logo

coqa-baselines's Introduction

StanfordNLP: A Python NLP Library for Many Human Languages

Travis Status PyPI Version Python Versions

⚠️ Note ⚠️

All development, issues, ongoing maintenance, and support have been moved to our new GitHub repository as the toolkit is being renamed as Stanza since version 1.0.0. Please visit our new website for more information. You can still download stanfordnlp via pip, but newer versions of this package will be made available as stanza. This repository is kept for archival purposes.

The Stanford NLP Group's official Python NLP library. It contains packages for running our latest fully neural pipeline from the CoNLL 2018 Shared Task and for accessing the Java Stanford CoreNLP server. For detailed information please visit our official website.

References

If you use our neural pipeline including the tokenizer, the multi-word token expansion model, the lemmatizer, the POS/morphological features tagger, or the dependency parser in your research, please kindly cite our CoNLL 2018 Shared Task system description paper:

@inproceedings{qi2018universal,
 address = {Brussels, Belgium},
 author = {Qi, Peng  and  Dozat, Timothy  and  Zhang, Yuhao  and  Manning, Christopher D.},
 booktitle = {Proceedings of the {CoNLL} 2018 Shared Task: Multilingual Parsing from Raw Text to Universal Dependencies},
 month = {October},
 pages = {160--170},
 publisher = {Association for Computational Linguistics},
 title = {Universal Dependency Parsing from Scratch},
 url = {https://nlp.stanford.edu/pubs/qi2018universal.pdf},
 year = {2018}
}

The PyTorch implementation of the neural pipeline in this repository is due to Peng Qi and Yuhao Zhang, with help from Tim Dozat and Jason Bolton.

This release is not the same as Stanford's CoNLL 2018 Shared Task system. The tokenizer, lemmatizer, morphological features, and multi-word term systems are a cleaned up version of the shared task code, but in the competition we used a Tensorflow version of the tagger and parser by Tim Dozat, which has been approximately reproduced in PyTorch (though with a few deviations from the original) for this release.

If you use the CoreNLP server, please cite the CoreNLP software package and the respective modules as described here ("Citing Stanford CoreNLP in papers"). The CoreNLP client is mostly written by Arun Chaganty, and Jason Bolton spearheaded merging the two projects together.

Issues and Usage Q&A

To ask questions, report issues or request features, please use the GitHub Issue Tracker.

Setup

StanfordNLP supports Python 3.6 or later. We strongly recommend that you install StanfordNLP from PyPI. If you already have pip installed, simply run:

pip install stanfordnlp

this should also help resolve all of the dependencies of StanfordNLP, for instance PyTorch 1.0.0 or above.

If you currently have a previous version of stanfordnlp installed, use:

pip install stanfordnlp -U

Alternatively, you can also install from source of this git repository, which will give you more flexibility in developing on top of StanfordNLP and training your own models. For this option, run

git clone https://github.com/stanfordnlp/stanfordnlp.git
cd stanfordnlp
pip install -e .

Running StanfordNLP

Getting Started with the neural pipeline

To run your first StanfordNLP pipeline, simply following these steps in your Python interactive interpreter:

>>> import stanfordnlp
>>> stanfordnlp.download('en')   # This downloads the English models for the neural pipeline
# IMPORTANT: The above line prompts you before downloading, which doesn't work well in a Jupyter notebook.
# To avoid a prompt when using notebooks, instead use: >>> stanfordnlp.download('en', force=True)
>>> nlp = stanfordnlp.Pipeline() # This sets up a default neural pipeline in English
>>> doc = nlp("Barack Obama was born in Hawaii.  He was elected president in 2008.")
>>> doc.sentences[0].print_dependencies()

The last command will print out the words in the first sentence in the input string (or Document, as it is represented in StanfordNLP), as well as the indices for the word that governs it in the Universal Dependencies parse of that sentence (its "head"), along with the dependency relation between the words. The output should look like:

('Barack', '4', 'nsubj:pass')
('Obama', '1', 'flat')
('was', '4', 'aux:pass')
('born', '0', 'root')
('in', '6', 'case')
('Hawaii', '4', 'obl')
('.', '4', 'punct')

Note: If you are running into issues like OSError: [Errno 22] Invalid argument, it's very likely that you are affected by a known Python issue, and we would recommend Python 3.6.8 or later and Python 3.7.2 or later.

We also provide a multilingual demo script that demonstrates how one uses StanfordNLP in other languages than English, for example Chinese (traditional)

python demo/pipeline_demo.py -l zh

See our getting started guide for more details.

Access to Java Stanford CoreNLP Server

Aside from the neural pipeline, this project also includes an official wrapper for acessing the Java Stanford CoreNLP Server with Python code.

There are a few initial setup steps.

  • Download Stanford CoreNLP and models for the language you wish to use
  • Put the model jars in the distribution folder
  • Tell the python code where Stanford CoreNLP is located: export CORENLP_HOME=/path/to/stanford-corenlp-full-2018-10-05

We provide another demo script that shows how one can use the CoreNLP client and extract various annotations from it.

Online Colab Notebooks

To get your started, we also provide interactive Jupyter notebooks in the demo folder. You can also open these notebooks and run them interactively on Google Colab. To view all available notebooks, follow these steps:

  • Go to the Google Colab website
  • Navigate to File -> Open notebook, and choose GitHub in the pop-up menu
  • Note that you do not need to give Colab access permission to your github account
  • Type stanfordnlp/stanfordnlp in the search bar, and click enter

Trained Models for the Neural Pipeline

We currently provide models for all of the treebanks in the CoNLL 2018 Shared Task. You can find instructions for downloading and using these models here.

Batching To Maximize Pipeline Speed

To maximize speed performance, it is essential to run the pipeline on batches of documents. Running a for loop on one sentence at a time will be very slow. The best approach at this time is to concatenate documents together, with each document separated by a blank line (i.e., two line breaks \n\n). The tokenizer will recognize blank lines as sentence breaks. We are actively working on improving multi-document processing.

Training your own neural pipelines

All neural modules in this library, including the tokenizer, the multi-word token (MWT) expander, the POS/morphological features tagger, the lemmatizer and the dependency parser, can be trained with your own CoNLL-U format data. Currently, we do not support model training via the Pipeline interface. Therefore, to train your own models, you need to clone this git repository and set up from source.

For detailed step-by-step guidance on how to train and evaluate your own models, please visit our training documentation.

LICENSE

StanfordNLP is released under the Apache License, Version 2.0. See the LICENSE file for more details.

coqa-baselines's People

Contributors

danqi avatar moinnadeem avatar sivareddyg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

coqa-baselines's Issues

Stanford CoreNLP: Error while loading a tagger model

Hi,

First of all, thank you for sharing the code which really helps!
I wanted to use your script to annotate the data (e.g., pos, ner). While using stanford CoreNLP to parse text, I got the following error:
edu.stanford.nlp.io.RuntimeIOException: Error while loading a tagger model (probably missing a model file)

FYI, following your instruction, I ran a CoreNLP server using the cmd: java -mx4g -cp lib/stanford-corenlp-3.9.1.jar edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000

Any help is highly appreciated!

import onmt.inputter error

I follow the readme
when I run the following command

python seq2seq/train.py -data data/seq2seq-h2 -save_model seq2seq_models/seq2seq -word_vec_size 300 -pre_word_vecs_enc data/seq2seq-h2.embed.enc.pt -pre_word_vecs_dec data/seq2seq-h2.embed.dec.pt -epochs 50 -gpuid 0 -seed 123

an error occurred

Traceback (most recent call last):
File "seq2seq/train.py", line 514, in
main()
File "seq2seq/train.py", line 488, in main
first_dataset = next(lazily_load_dataset("train"))
File "seq2seq/train.py", line 337, in lazily_load_dataset
yield lazy_dataset_loader(pt, corpus_type)
File "seq2seq/train.py", line 328, in lazy_dataset_loader
dataset = torch.load(pt_file)
File "/home/zhengquan/anaconda3/envs/coqa/lib/python3.6/site-packages/torch/serialization.py", line 358, in load
return _load(f, map_location, pickle_module)
File "/home/zhengquan/anaconda3/envs/coqa/lib/python3.6/site-packages/torch/serialization.py", line 542, in _load
result = unpickler.load()
ModuleNotFoundError: No module named 'onmt.inputters'

Permanently added 'github.com,192.30.253.112' (RSA) to the list of known hosts

git clone --recurse-submodules [email protected]:stanfordnlp/coqa-baselines.git

Cloning into 'coqa-baselines'...
The authenticity of host 'github.com (192.30.253.112)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.253.112' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Problem running the code

I have Python 3.6.8 with Pytorch=0.4.1, torchtext=0.2.1, gensim and pycorenlp install.
Following the steps to run the code, the url (http://central.maven.org/maven2/edu/stanford/nlp/stanford-corenlp/3.9.1/stanford-corenlp-3.9.1.jar) does not work however i manage to find the .jar file.

When i tried to run the Preprocessing section (of Conversational models) i managed to run the first 3 commands, but when i run the 4th command (PYTHONPATH=seq2seq python seq2seq/tools/embeddings_to_torch.py -emb_file_enc wordvecs/glove.42B.300d.txt -emb_file_dec wordvecs/glove.42B.300d.txt -dict_file data/seq2seq-h2.vocab.pt -output_file data/seq2seq-h2.embed) an error occurs:

Traceback (most recent call last):
File "seq2seq/tools/embeddings_to_torch.py", line 10, in
from onmt.Utils import get_logger
ModuleNotFoundError: No module named 'onmt'

additional answers

is the 'additional_answers' field from the original training data ever used for anything?

I can't get paper's score of DrQA + PGnet.

I can't get paper's score of DrQA + PGnet.
I used the pipeline model and n_history is 0.
I think the dev is 61.5, but the result is not.
I used CoQA evaluation script for evaluation.
python evaluate-v1.0.py
--data-file data/coqa-dev-v1.0.json
--pred-file pipeline_models/pipeline.prediction.json

The result is here.
{
"children_stories": {
"em": 11.5,
"f1": 13.7,
"turns": 1425
},
"literature": {
"em": 12.7,
"f1": 13.9,
"turns": 1630
},
"mid-high_school": {
"em": 12.4,
"f1": 14.3,
"turns": 1653
},
"news": {
"em": 10.0,
"f1": 11.1,
"turns": 1649
},
"wikipedia": {
"em": 9.6,
"f1": 11.0,
"turns": 1626
},
"reddit": {
"em": 0.0,
"f1": 0.0,
"turns": 0
},
"science": {
"em": 0.0,
"f1": 0.0,
"turns": 0
},
"in_domain": {
"em": 11.2,
"f1": 12.7,
"turns": 7983
},
"out_domain": {
"em": 0.0,
"f1": 0.0,
"turns": 0
},
"overall": {
"em": 11.2,
"f1": 12.7,
"turns": 7983
}
}

When I used only DrQA, the score is as expected.
I think DrQA predicts the answer,but DrQA must predict Evidence in the pipeline model.
Thank you!

how to set a proper -train_steps during training a coqa-base model

background: because of the changing of the parameters in the latest OpenNMT-py version , the parameter "-epochs " has changed to "-train_steps".

question: If I need to train Conversational models and The pipeline model, how to set a proper -train_steps instead of -epochs.Do I need to git clone the older OpenNMT-py version?

RuntimeError: generator raised StopIteration when preprocessing for Conversational models

python seq2seq/preprocess.py -train_src data/seq2seq-train-h2-src.txt -train_tgt data/seq2seq-train-h2-tgt.txt -valid_src data/seq2seq-dev-h2-src.txt -valid_tgt data/seq2seq-dev-h2-tgt.txt -save_data data/seq2seq-h2 -lower -dynamic_dict -src_seq_length 10000

[2018-12-30 10:40:29,810 INFO] Extracting features...
[2018-12-30 10:40:29,812 INFO]  * number of source features: 0.
[2018-12-30 10:40:29,812 INFO]  * number of target features: 0.
[2018-12-30 10:40:29,812 INFO] Building `Fields` object...
[2018-12-30 10:40:29,812 INFO] Building & saving training data...
Traceback (most recent call last):
  File "/Users/jatinganhotra/deep-learning/CoQA/coqa-baselines/seq2seq/onmt/io/TextDataset.py", line 368, in __iter__
    raise StopIteration
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "seq2seq/preprocess.py", line 204, in <module>
    main()
  File "seq2seq/preprocess.py", line 194, in main
    train_dataset_files = build_save_dataset('train', fields, opt, logger)
  File "seq2seq/preprocess.py", line 134, in build_save_dataset
    corpus_type, opt)
  File "seq2seq/preprocess.py", line 103, in build_save_text_dataset_in_shards
    dynamic_dict=opt.dynamic_dict)
  File "/Users/jatinganhotra/deep-learning/CoQA/coqa-baselines/seq2seq/onmt/io/TextDataset.py", line 78, in __init__
    for ex_values in example_values:
  File "/Users/jatinganhotra/deep-learning/CoQA/coqa-baselines/seq2seq/onmt/io/TextDataset.py", line 70, in <genexpr>
    example_values = ([ex[k] for k in keys] for ex in examples_iter)
  File "/Users/jatinganhotra/deep-learning/CoQA/coqa-baselines/seq2seq/onmt/io/TextDataset.py", line 271, in _dynamic_dict
    for example in examples_iter:
  File "/Users/jatinganhotra/deep-learning/CoQA/coqa-baselines/seq2seq/onmt/io/TextDataset.py", line 56, in <genexpr>
    examples_iter = (self._join_dicts(src, tgt) for src, tgt in
RuntimeError: generator raised StopIteration

The version for packages installed are:

→ python -V
Python 3.7.1

→ pip list
Package         Version
--------------- ----------
boto            2.49.0
boto3           1.9.71
botocore        1.12.71
bz2file         0.98
certifi         2018.11.29
cffi            1.11.5
chardet         3.0.4
docutils        0.14
gensim          3.6.0
idna            2.8
jmespath        0.9.3
mkl-fft         1.0.6
mkl-random      1.0.2
numpy           1.15.4
olefile         0.46
Pillow          5.3.0
pip             18.1
pycorenlp       0.3.0
pycparser       2.19
python-dateutil 2.7.5
requests        2.21.0
s3transfer      0.1.13
scipy           1.2.0
setuptools      40.6.3
six             1.12.0
smart-open      1.7.1
torch           1.0.0
torchtext       0.2.1
torchvision     0.2.1
tqdm            4.28.1
urllib3         1.24.1
wheel           0.32.3

Can we read the previous gold answers while predict?

Hi, I am recently working on CoQA, and I want to ask something about the details during the official evaluating.
So is it allowed to get the previous gold answers while the model is trying to predict some question?
Our model need to get the previous questions and answers from the first to the one before the current question to be predicted and I mean could I read the gold answers from the json-file like the validation locally or it is only allowed to use the answers the model predicted by it-self? I see that your baseline have appended the ground truth answers to the input so I wanna know is it allowed while officially evaluating.
Thanks for your help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.