kiwi.predictors package

Submodules

kiwi.predictors.linear_tester module

A generic implementation of a basic tester.

class kiwi.predictors.linear_tester.LinearTester(classifier)[source]

Bases: object

run(dataset, **kwargs)[source]

kiwi.predictors.predictor module

class kiwi.predictors.predictor.Predicter(model, fields=None)[source]

Bases: object

predict(examples, batch_size=1)[source]

Create Predictions for a list of examples.

Parameters:
  • examples – A dict mapping field names to the list of raw examples (strings).
  • batch_size – Batch Size to use. Default 1.
Returns:

A dict mapping prediction levels (word, sentence ..) to the model predictions for each example.

Raises:

Exception – If an example has an empty string as source or target field.

Example

>>> import kiwi
>>> predictor = kiwi.load_model('tests/toy-data/models/nuqe.torch')
>>> src = ['a b c', 'd e f g']
>>> tgt = ['q w e r', 't y']
>>> align = ['0-0 1-1 1-2', '1-1 3-0']
>>> examples = {kiwi.constants.SOURCE: src,
                kiwi.constants.TARGET: tgt,
                kiwi.constants.ALIGNMENTS: align}
>>> predictor.predict(examples)
{'tags': [[0.4760947525501251,
   0.47569847106933594,
   0.4948718547821045,
   0.5305878520011902],
  [0.5105430483818054, 0.5252899527549744]]}
run(dataset, batch_size=1)[source]
to(device)[source]

Method to mode Predicter object to other device. e.g: “cuda”

Parameters:device (str) – Device to which the model should be move to.

Module contents