osanseviero HF staff commited on
Commit
ee8d8d5
1 Parent(s): 0e32675

Create pipeline.py

Browse files
Files changed (1) hide show
  1. pipeline.py +36 -0
pipeline.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from typing import Dict, List, Any
3
+
4
+ class PreTrainedPipeline():
5
+ def __init__(self, path=""):
6
+ # IMPLEMENT_THIS
7
+ # Preload all the elements you are going to need at inference.
8
+ # For instance your model, processors, tokenizer that might be needed.
9
+ # This function is only called once, so do all the heavy processing I/O here"""
10
+ Initialize model
11
+ """
12
+ package = os.path.join(path,"en_core_web_sm-any-py3-none-any.whl")
13
+ subprocess.check_call(
14
+ [sys.executable, "-m", "pip", "install", package]
15
+ )
16
+ raise NotImplementedError(
17
+ "Please implement TokenClassificationPipeline __init__ function"
18
+ )
19
+
20
+ def __call__(self, inputs: str) -> List[Dict[str, Any]]:
21
+ """
22
+ Args:
23
+ inputs (:obj:`str`):
24
+ a string containing some text
25
+ Return:
26
+ A :obj:`list`:. The object returned should be like [{"entity_group": "XXX", "word": "some word", "start": 3, "end": 6, "score": 0.82}] containing :
27
+ - "entity_group": A string representing what the entity is.
28
+ - "word": A substring of the original string that was detected as an entity.
29
+ - "start": the offset within `input` leading to `answer`. context[start:stop] == word
30
+ - "end": the ending offset within `input` leading to `answer`. context[start:stop] === word
31
+ - "score": A score between 0 and 1 describing how confident the model is for this entity.
32
+ """
33
+ # IMPLEMENT_THIS
34
+ raise NotImplementedError(
35
+ "Please implement TokenClassificationPipeline __call__ function"
36
+ )