Git Product home page Git Product logo

allennlp_tutorial's Introduction

AllenNLP Tutorial

New: July 20, 2020: The tutorial now uses AllenNLP 1.0, and so should be up-to-date with the latest AllenNLP.

This tutorial is meant to teach you both how to use AllenNLP and a principled approach to doing deep learning research in NLP. The content is mirrored (and updated) on my personal site: jbarrow.ai. If you're interested in reading the latest version, you can find it there. But the code will always be stored in this repository. It consists of 10 sections, and I recommend you do them in order:

  1. Setup
  2. Building a Dataset Reader
  3. Building a Baseline Model
  4. Configuring Experiments
  5. Tackling Your Own Experiments
  6. Predictors
  7. Debugging [WIP]
  8. Advanced Modeling: Hierarchical LSTMs, CRF Decoding, and BERT [WIP]
  9. Digging Into the Documentation [WIP]
  10. Hyperparameter Search: AllenTune [WIP]
  11. Appendix: Migrating from AllenNLP 0.9 to 1.0 [WIP]

The tutorial makes no assumptions about familiarity with AllenNLP, and goes through using it as an experimental platform, using JSON configurations.

allennlp_tutorial's People

Contributors

bolducp avatar cjber avatar gillesj avatar jbarrow avatar jbrry avatar sidenver avatar urieli 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

allennlp_tutorial's Issues

When will you write later tutorials?

Thanks so much for your tutorials, I learned a lot from these tutorials about allennlp.
I wonder when will you write later tutorials?
Thank you agagin for your kindness!

lesson 1

allennlp train --dry-run --include-package tagging -s /tmp/tagging/tests/0 configs/test_reader.jsonnet

could you please explain this line in more details especially /tmp/tagging/tests/0
where could I find /tmp/tagging/tests/0
how to read it and how to interpret it?

config file

Could you please provide us with a complete step by step tutorial of building config file, what should be included what should not and why?. I have noticed that not all parameters in __init __is included in jsonnet file which confused me. How can I decide to include a parameter of init in jsonnet file and when not?

How to evaluate the model in another set?

Hello @jbarrow, thank you for this fantastic tutorial. I trained the model using the training and validation sets. Now I want to evaluate the model with the test set. I used the following command:

allennlp evaluate model.tar.gz test.txt --include-package tagging

However, it returns zero metrics.

    "precision-overall": 0.0,
    "recall-overall": 0.0,
    "f1-measure-overall": 0.0,

Could you tell me what is the correct way to do that? Thank you so much!

Raised error while testing reader test_reader.jsonnet

I used your configuration then get an error like this any idea ? ;

raise ConfigurationError("The 'vocabulary' directory in the provided " allennlp.common.checks.ConfigurationError: "The 'vocabulary' directory in the provided serialization directory is non-empty"

Thanks for your helps :)

The pesky error

Your tutorial is very good!

Is this the pesky error you mentioned in the ‘1. Building a Dataset Reader’?

allennlp.common.checks.ConfigurationError: 'key "model" is required at location ""'

There is a bug in the configs/train_lstm.jsonnet file

command:

allennlp train -f --include-package tagging -s /tmp/tagging/lstm configs/train_lstm.jsonnet

ERROR:

2021-03-02 12:25:12,430 - INFO - allennlp.modules.token_embedders.embedding - Reading pretrained embeddings from file
2021-03-02 12:25:13,722 - INFO - allennlp.common.file_utils - cache of http://nlp.stanford.edu/data/glove.6B.zip is up-to-date
2021-03-02 12:25:14,726 - INFO - allennlp.common.file_utils - cache of http://nlp.stanford.edu/data/glove.6B.zip is up-to-date
400000it [00:02, 149772.39it/s]
2021-03-02 12:25:17,402 - CRITICAL - root - Uncaught exception
Traceback (most recent call last):
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/bin/allennlp", line 8, in
sys.exit(run())
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/main.py", line 34, in run
main(prog="allennlp")
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/commands/init.py", line 119, in main
args.func(args)
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/commands/train.py", line 119, in train_model_from_args
file_friendly_logging=args.file_friendly_logging,
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/commands/train.py", line 178, in train_model_from_file
file_friendly_logging=file_friendly_logging,
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/commands/train.py", line 242, in train_model
file_friendly_logging=file_friendly_logging,
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/commands/train.py", line 456, in train_worker
local_rank=process_rank,
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/common/from_params.py", line 604, in from_params
**extras,
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/common/from_params.py", line 634, in from_params
return constructor_to_call(**kwargs) # type: ignore
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/commands/train.py", line 712, in from_partial_objects
model
= model.construct(vocab=vocabulary_, serialization_dir=serialization_dir)
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/common/lazy.py", line 62, in construct
return self._constructor(**kwargs)
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/common/from_params.py", line 470, in constructor
return value_cls.from_params(params=deepcopy(popped_params), **constructor_extras)
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/common/from_params.py", line 604, in from_params
**extras,
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/common/from_params.py", line 632, in from_params
kwargs = create_kwargs(constructor_to_inspect, cls, params, **extras)
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/common/from_params.py", line 200, in create_kwargs
cls.name, param_name, annotation, param.default, params, **extras
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/common/from_params.py", line 307, in pop_and_construct_arg
return construct_arg(class_name, name, popped_params, annotation, default, **extras)
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/common/from_params.py", line 341, in construct_arg
return annotation.from_params(params=popped_params, **subextras)
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/common/from_params.py", line 604, in from_params
**extras,
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/common/from_params.py", line 632, in from_params
kwargs = create_kwargs(constructor_to_inspect, cls, params, **extras)
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/common/from_params.py", line 200, in create_kwargs
cls.name, param_name, annotation, param.default, params, **extras
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/common/from_params.py", line 307, in pop_and_construct_arg
return construct_arg(class_name, name, popped_params, annotation, default, **extras)
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/common/from_params.py", line 391, in construct_arg
**extras,
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/common/from_params.py", line 341, in construct_arg
return annotation.from_params(params=popped_params, **subextras)
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/common/from_params.py", line 604, in from_params
**extras,
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/common/from_params.py", line 634, in from_params
return constructor_to_call(**kwargs) # type: ignore
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/modules/token_embedders/embedding.py", line 156, in init
pretrained_file, embedding_dim, vocab, vocab_namespace
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/modules/token_embedders/embedding.py", line 370, in _read_pretrained_embeddings_file
return _read_embeddings_from_text_file(file_uri, embedding_dim, vocab, namespace)
File "/home/s2020017/Anaconda_3.7/envs/owl2vec3/lib/python3.7/site-packages/allennlp/modules/token_embedders/embedding.py", line 418, in _read_embeddings_from_text_file
"No embeddings of correct dimension found; you probably "
allennlp.common.checks.ConfigurationError: No embeddings of correct dimension found; you probably misspecified your embedding_dim parameter, or didn't pre-populate your Vocabulary

lesson 3

I got this error

(base) arij@arij-HP-ProBook-450-G4:~/allennlp_tutorial$ allennlp train -f --include-package tagging -s /tmp/tagging/lstm configs/train_lstm.jsonnet
2020-09-16 07:13:12,680 - INFO - allennlp.common.params - random_seed = 13370
2020-09-16 07:13:12,681 - INFO - allennlp.common.params - numpy_seed = 1337
2020-09-16 07:13:12,681 - INFO - allennlp.common.params - pytorch_seed = 133
2020-09-16 07:13:12,690 - INFO - allennlp.common.checks - Pytorch version: 1.6.0
2020-09-16 07:13:12,690 - INFO - allennlp.common.params - type = default
2020-09-16 07:13:12,691 - INFO - allennlp.common.params - dataset_reader.type = conll_03_reader
2020-09-16 07:13:12,691 - INFO - allennlp.common.params - dataset_reader.token_indexers = None
2020-09-16 07:13:12,691 - INFO - allennlp.common.params - dataset_reader.lazy = False
2020-09-16 07:13:12,691 - INFO - allennlp.common.params - train_data_path = data/train.txt
2020-09-16 07:13:12,692 - INFO - allennlp.common.params - vocabulary = None
2020-09-16 07:13:12,692 - INFO - allennlp.common.params - datasets_for_vocab_creation = None
2020-09-16 07:13:12,692 - INFO - allennlp.common.params - validation_dataset_reader = None
2020-09-16 07:13:12,692 - INFO - allennlp.common.params - validation_data_path = data/validation.txt
2020-09-16 07:13:12,692 - INFO - allennlp.common.params - validation_data_loader = None
2020-09-16 07:13:12,692 - INFO - allennlp.common.params - test_data_path = None
2020-09-16 07:13:12,692 - INFO - allennlp.common.params - evaluate_on_test = False
2020-09-16 07:13:12,692 - INFO - allennlp.common.params - batch_weight_key =
2020-09-16 07:13:12,692 - INFO - allennlp.training.util - Reading training data from data/train.txt
reading instances: 14987it [00:00, 22660.99it/s]
2020-09-16 07:13:13,354 - INFO - allennlp.training.util - Reading validation data from data/validation.txt
reading instances: 3466it [00:00, 14769.80it/s]
2020-09-16 07:13:13,589 - INFO - allennlp.data.vocabulary - Fitting token dictionary from dataset.
building vocab: 18453it [00:00, 94424.38it/s]
2020-09-16 07:13:13,822 - CRITICAL - root - Uncaught exception
Traceback (most recent call last):
File "/home/arij/anaconda3/lib/python3.8/site-packages/allennlp/common/params.py", line 238, in pop
value = self.params.pop(key)
KeyError: 'type'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/arij/anaconda3/bin/allennlp", line 8, in
sys.exit(run())
File "/home/arij/anaconda3/lib/python3.8/site-packages/allennlp/main.py", line 34, in run
main(prog="allennlp")
File "/home/arij/anaconda3/lib/python3.8/site-packages/allennlp/commands/init.py", line 92, in main
args.func(args)
File "/home/arij/anaconda3/lib/python3.8/site-packages/allennlp/commands/train.py", line 109, in train_model_from_args
train_model_from_file(
File "/home/arij/anaconda3/lib/python3.8/site-packages/allennlp/commands/train.py", line 169, in train_model_from_file
return train_model(
File "/home/arij/anaconda3/lib/python3.8/site-packages/allennlp/commands/train.py", line 232, in train_model
model = train_worker(
File "/home/arij/anaconda3/lib/python3.8/site-packages/allennlp/commands/train.py", line 430, in train_worker
train_loop = TrainModel.from_params(
File "/home/arij/anaconda3/lib/python3.8/site-packages/allennlp/common/from_params.py", line 591, in from_params
return retyped_subclass.from_params(
File "/home/arij/anaconda3/lib/python3.8/site-packages/allennlp/common/from_params.py", line 624, in from_params
return constructor_to_call(**kwargs) # type: ignore
File "/home/arij/anaconda3/lib/python3.8/site-packages/allennlp/commands/train.py", line 648, in from_partial_objects
model
= model.construct(vocab=vocabulary
)
File "/home/arij/anaconda3/lib/python3.8/site-packages/allennlp/common/lazy.py", line 46, in construct
return self._constructor(**kwargs)
File "/home/arij/anaconda3/lib/python3.8/site-packages/allennlp/common/from_params.py", line 461, in constructor
return value_cls.from_params(params=deepcopy(popped_params), **constructor_extras)
File "/home/arij/anaconda3/lib/python3.8/site-packages/allennlp/common/from_params.py", line 572, in from_params
choice = params.pop_choice(
File "/home/arij/anaconda3/lib/python3.8/site-packages/allennlp/common/params.py", line 342, in pop_choice
value = self.pop(key, default)
File "/home/arij/anaconda3/lib/python3.8/site-packages/allennlp/common/params.py", line 243, in pop
raise ConfigurationError(msg)
allennlp.common.checks.ConfigurationError: key "type" is required at location "model."

5_predictors

We're going to look at the first two of these, but if you're interested in using AllenNLP to serve models in production, you should definitely take a look at allennlp serve.

the link for allennlp serve is not valid, the page didn't work

It would be great if it is possible to provide us with complete example of how to use predictors as service

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.