Update readme
Browse files
README.md
CHANGED
@@ -1,3 +1,99 @@
|
|
1 |
---
|
|
|
|
|
|
|
|
|
2 |
license: mit
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
tags:
|
3 |
+
- text-classification
|
4 |
+
widget:
|
5 |
+
- text: "Hosted inference API not supported"
|
6 |
license: mit
|
7 |
+
language: en
|
8 |
---
|
9 |
+
|
10 |
+
# Multi2ConvAI-Logistics: English logistic regression model using fasttext embeddings
|
11 |
+
|
12 |
+
This model was developed in the [Multi2ConvAI](https://multi2conv.ai) project:
|
13 |
+
- domain: Logistics (more details about our use cases: ([en](https://multi2convai/en/blog/use-cases), [de](https://multi2convai/en/blog/use-cases)))
|
14 |
+
- language: English (en)
|
15 |
+
- model type: logistic regression
|
16 |
+
- embeddings: fastText embeddings
|
17 |
+
|
18 |
+
## How to run
|
19 |
+
|
20 |
+
Requires:
|
21 |
+
- [multi2convai](https://github.com/inovex/multi2convai)
|
22 |
+
- serialized fastText embeddings (see last section of this readme or [these instructions](https://github.com/inovex/multi2convai/models/embeddings.README.md))
|
23 |
+
|
24 |
+
### Run with one line of code
|
25 |
+
|
26 |
+
After installing `multi2convai` and locally available fastText embeddings you can run:
|
27 |
+
|
28 |
+
````bash
|
29 |
+
# assumes working dir is the root of the cloned multi2convai repo
|
30 |
+
|
31 |
+
python scripts/run_inference.py -m multi2convai-logistics-en-logreg-ft
|
32 |
+
|
33 |
+
>>> Create pipeline for config: multi2convai-logistics-en-logreg-ft.
|
34 |
+
>>> Created a LogisticRegressionFasttextPipeline for domain: 'logistics' and language 'en'.
|
35 |
+
>>>
|
36 |
+
>>> Enter your text (type 'stop' to end execution): Muss ich eine Maske tragen?
|
37 |
+
>>> 'Where can I put the parcel?' was classified as 'details.safeplace' (confidence: 0.8943)
|
38 |
+
````
|
39 |
+
|
40 |
+
### How to run model using multi2convai
|
41 |
+
|
42 |
+
After installing `multi2convai` and locally available fastText embeddings you can run:
|
43 |
+
|
44 |
+
````python
|
45 |
+
# assumes working dir is the root of the cloned multi2convai repo
|
46 |
+
|
47 |
+
from pathlib import Path
|
48 |
+
|
49 |
+
from multi2convai.pipelines.inference.base import ClassificationConfig
|
50 |
+
from multi2convai.pipelines.inference.logistic_regression_fasttext import (
|
51 |
+
LogisticRegressionFasttextConfig,
|
52 |
+
LogisticRegressionFasttextPipeline,
|
53 |
+
)
|
54 |
+
|
55 |
+
language = "de"
|
56 |
+
domain = "logistics"
|
57 |
+
|
58 |
+
# 1. Define paths of model, label dict and embeddings
|
59 |
+
model_file = "model.pth"
|
60 |
+
label_dict_file = "label_dict.json"
|
61 |
+
|
62 |
+
embedding_path = Path(
|
63 |
+
f"../models/embeddings/fasttext/en/wiki.200k.en.embed"
|
64 |
+
)
|
65 |
+
vocabulary_path = Path(
|
66 |
+
f"../models/embeddings/fasttext/en/wiki.200k.en.vocab"
|
67 |
+
)
|
68 |
+
|
69 |
+
# 2. Create and setup pipeline
|
70 |
+
model_config = LogisticRegressionFasttextConfig(
|
71 |
+
model_file, embedding_path, vocabulary_path
|
72 |
+
)
|
73 |
+
config = ClassificationConfig(language, domain, label_dict_file, model_config)
|
74 |
+
|
75 |
+
pipeline = LogisticRegressionFasttextPipeline(config)
|
76 |
+
pipeline.setup()
|
77 |
+
|
78 |
+
# 3. Run intent classification on a text of your choice
|
79 |
+
label = pipeline.run("Where can I put the parcel?")
|
80 |
+
label
|
81 |
+
>>> Label(string='details.safeplace', ratio='0.8943')
|
82 |
+
````
|
83 |
+
|
84 |
+
### Download and serialize fastText
|
85 |
+
````bash
|
86 |
+
# assumes working dir is the root of the cloned multi2convai repo
|
87 |
+
|
88 |
+
mkdir models/fasttext/en
|
89 |
+
curl https://dl.fbaipublicfiles.com/fasttext/vectors-wiki/wiki.en.vec --output models/fasttext/en/wiki.en.vec
|
90 |
+
|
91 |
+
python scripts/serialize_fasttext.py -r fasttext/wiki.en.vec -v fasttext/en/wiki.200k.en.vocab -e fasttext/en/wiki.200k.en.embed -n 200000
|
92 |
+
|
93 |
+
|
94 |
+
````
|
95 |
+
|
96 |
+
## Further information on Multi2ConvAI:
|
97 |
+
- https://multi2conv.ai
|
98 |
+
- https://github.com/inovex/multi2convai
|
99 |
+
- mailto: info@multi2conv.ai
|