GithubHelp home page GithubHelp logo

stanfordnlp / phrasenode Goto Github PK

View Code? Open in Web Editor NEW
37.0 37.0 13.0 265 KB

Mapping natural language commands to web elements

License: Other

Python 70.20% Dockerfile 0.20% JavaScript 29.03% Shell 0.58%

phrasenode'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.

phrasenode's People

Contributors

codeslord avatar kambehmw avatar ppasupat avatar qbit23 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

Watchers

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

phrasenode's Issues

Training existing model for new data

Hi, how can I fit an existing model to new training data?
At the moment, I have to run the whole training process from scratch on old data+ new data. Is there a way to load an existing model and train it only on the added new data? In other words, is there a way for an existing model to learn on the fly for new training data?
I went through the argument parser in main.py but could not find any arguments to handle this case.

Tensor size mismatch when use_neighbors set to True

Hi, I am trying to run the embedding model with visual neighbors included, and run into a tensor size mismatch between the expected size of the score linear layer and the encoding input dimensions.

Training:   0%|          | 0/30000 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "./main.py", line 87, in <module>
    run.train()
  File "/research/aburns4/phrasenode/phrasenode/training_run.py", line 138, in train
    web_page_code, examples, train=True, logfile=self.logfile)
  File "/research/aburns4/phrasenode/phrasenode/training_run.py", line 212, in _process_examples
    logits, losses, predictions = self.model(web_page, examples)
  File "/scratch2/pnenv/lib/python2.7/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/research/aburns4/phrasenode/phrasenode/model/encoding.py", line 128, in forward
    scores = self.score(encoding)
  File "/scratch2/pnenv/lib/python2.7/site-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
  File "/scratch2/pnenv/lib/python2.7/site-packages/torch/nn/modules/linear.py", line 87, in forward
    return F.linear(input, self.weight, self.bias)
  File "/scratch2/pnenv/lib/python2.7/site-packages/torch/nn/functional.py", line 1370, in linear
    ret = torch.addmm(bias, input, weight.t())
RuntimeError: size mismatch, m1: [414 x 700], m2: [1100 x 1] at /pytorch/aten/src/THC/generic/THCTensorMathBlas.cu:290

I presume something might be wrong in the self.encode_dim calculation (such as the extra_nodes value) that's causing this. Any help would be appreciated! I am able to run the embedding model with use_neighbors set to False, as well as the alignment model with and without the visual neighbors. Thank you!

Which versions are cuda and pytorch?

When training with cuda 10.1 and latest pytorch 1.3.1, I get the following error.

Traceback (most recent call last):
  File "./main.py", line 87, in <module>
    run.train()
  File "/home/kambe/works/phrasenode/phrasenode/training_run.py", line 138, in train
    web_page_code, examples, train=True, logfile=self.logfile)
  File "/home/kambe/works/phrasenode/phrasenode/training_run.py", line 212, in _process_examples
    logits, losses, predictions = self.model(web_page, examples)
  File "/home/kambe/miniconda3/envs/py27-phrasenode/lib/python2.7/site-packages/torch/nn/modules/module.py", line 541, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/kambe/works/phrasenode/phrasenode/model/encoding.py", line 151, in forward
    if not np.isfinite(losses.data.sum()):
  File "/home/kambe/miniconda3/envs/py27-phrasenode/lib/python2.7/site-packages/torch/tensor.py", line 449, in __array__
    return self.numpy()
TypeError: can't convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

Does it probably work with the following versions?

  • cuda 9.0
  • pytorch 1.1.0

please specify the details of the version in the readme file.

License

Hi,

We want to use your module for one project.
Can you tell us what the license is?

xid creation in dataset

Hi,

I was wondering if you could explain how you obtained the 'xid' values for the annotations in the dataset. Did you perform breadth or depth first search and number elements in the DOM according to the traversal? Were there any other specifications to count the elements, such as whether they were visible or not?

Thank you!

Equivalent Nodes In Dataset

I'm wondering how the list of equiv nodes are generated in the dataset. From my understanding of the paper, crowdworkers reference exactly one element, but there is a list of xids in the dataset. Were there additional manual annotations in a later step to find equivalent nodes to xid, or were the equivalent nodes programmatically generated?

Below is an example from combined-v2-cleaned.train.jsonl. Thanks!

{"equiv": [133, 135, 139], "exampleId": "32N49TQG3HCKR3W5C65VPBKPDP4AV2_a1", "phrase": "click first article", " version": "v6", "webpage": "247wallst.com", "xid": 133}

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.