Switch to unified view

a b/guide/walkthrough/model_utilization.md
1
# Using our medaCy Trained Model
2
3
Once a medaCy model has been trained - it can be saved, distributed, and used for prediction.
4
To predict with a trained learning model, it is required that documents be run through a pipeline identical to that which the model was trained with. Fortunately, medaCy encapsulates this functionality via the `Model` class.
5
6
7
## Loading a trained model for prediction
8
Once a CRF model has been trained and saved to disk, it can be loaded again for use by configuring a `Model` object with the pipeline used to train the CRF model. The below example shows how to configure the medaCy clinical model.
9
10
```python
11
from medacy.pipelines import ClinicalPipeline
12
from medacy.model.model import Model
13
14
pipeline = ClinicalPipeline(metamap=None, entities=['Drug'])
15
model = Model(pipeline)
16
model.load('/home/medacy/trained_model.pickle')
17
18
annotation = model.predict("The patient took 5 mg of aspirin.")  # Returns an Annotations object
19
```
20
21
Model prediction over a string returns a medaCy `Annotations` object. 
22
Useful functionalities are provided in the `Annotation` class such as the ability to see a *diff* between 
23
two annotations for empirical analysis.
24
25
Trained CRF models are [pickled](https://docs.python.org/3/library/pickle.html) (serialized) binary files.
26
27
## medaCy Model Management
28
29
One of medaCy's most powerful features is the ability to maintain, version and distribute medaCy compatible models with ease. The idea is simple - all the set-up code for a `Model` including a trained machine learning model is abstracted into an outside installable python package. This allows one to maintain the model with a version history just like any piece of software.
30
31
Once a model has been [packaged](packaging_a_medacy_model.md) and installed it can be used as follows:
32
33
```python
34
from medacy.model.model import Model
35
36
model = Model.load_external('medacy_model_clinical_notes')
37
annotations = model.predict("The patient took 5 mg of aspirin.")
38
```
39
40
See [Packaging a medaCy Model](packaging_a_medacy_model.md) for information on how to distribute your own trained models either internally or to the world.