Skip to main content

Hydra plugin for allennlp

Project description

AllenNLP-Hydra

Plugin For AllenNLP that enables composing configs through the use of the Hydra Library from Facebook Research.

NOTE there is no affiliation between this project and AllenNLP or the Allen Institute for AI.

We use the same contributions guideline as AllenNLP in order to maintain similar code styles. For this reason our style guide is the same as that found in their repository.

Install Instructions

Clone the repo

pip install .
echo allennlp_hydra >> ~.allennlp_plugins

The second line adds allennlp-hydra to the allennlp plugins file so that it can globally be recognized.

Basic Guide

Say you have the following directory structure:

project
+-- conf
|   +-- dataset_readers
|   |   +-- A.yaml
|   |   +-- B.yaml
|   +-- models
|   |   +-- C.yaml
|   |   +-- D.yaml
|   +-- config.yaml
+-- experiments

conf/dataset_readers/A.yaml:

type: A
start_token: <s>
end_token: </s>

conf/dataset_readers/B.yaml:

type: B
start_token: [CLS]
end_token: [SEP]

conf/models/C.yaml:

type: C
layers: 5

conf/models/D.yaml:

type: D
input_dim: 10

config.yaml

defaults:
    - dataset_reader: A
    - model: C

debug: false

Then running the command

allennlp compose conf config example -s experiments

Produces the file project/experiments/config.json

{
    "dataset_reader":{
        "type": "A",
        "start_token": "<s>",
        "end_token": "</s>"
    },
    "model": {
        "type": "C",
        "layers": 5
    },
    "debug": false
}

If you want to override the config and use the B dataset reader with the D model, you would modify the previous command:

allennlp compose conf config example -s experiments -o model=D dataset_reader=B

Produces the file project/experiments/config.json

{
    "dataset_reader":{
        "type": "B",
        "start_token": "[CLS]",
        "end_token": "[SEP]"
    },
    "model": {
        "type": "D",
        "input_dim": 10
    },
    "debug": false
}

And if you wanted to change input_dim of model D to 25:

allennlp compose conf config example -s experiments -o model=D dataset_reader=B model.input_dim=25

Produces the file project/experiments/config.json

{
    "dataset_reader":{
        "type": "B",
        "start_token": "[CLS]",
        "end_token": "[SEP]"
    },
    "model": {
        "type": "D",
        "input_dim": 25
    },
    "debug": false
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

allennlp-hydra-0.0.7.tar.gz (15.3 kB view hashes)

Uploaded Source

Built Distribution

allennlp_hydra-0.0.7-py3-none-any.whl (18.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page