BioMike commited on
Commit
38cc873
1 Parent(s): 74e1cd8

Update interfaces/base_pipeline.py

Browse files
Files changed (1) hide show
  1. interfaces/base_pipeline.py +41 -41
interfaces/base_pipeline.py CHANGED
@@ -1,42 +1,42 @@
1
- from utca.core import RenameAttribute,Flush
2
- from utca.implementation.predictors import TokenSearcherPredictor, TokenSearcherPredictorConfig
3
- from utca.implementation.tasks import TokenSearcherNER, TokenSearcherNERPostprocessor
4
- from utca.implementation.predictors.token_searcher.token_searcher_pipeline import TokenClassificationPipeline
5
- from transformers import AutoTokenizer, AutoModelForTokenClassification
6
-
7
- predictor = TokenSearcherPredictor(
8
- TokenSearcherPredictorConfig(
9
- model_name = "knowledgator/UTC-DeBERTa-large-v2",
10
- device="cpu"
11
- )
12
- )
13
-
14
- def generate_pipeline(threshold: float = 0.5):
15
- ner_task = TokenSearcherNER(
16
- predictor=predictor,
17
- postprocess=TokenSearcherNERPostprocessor(
18
- threshold=threshold
19
- )
20
- )
21
- pipeline = (
22
- ner_task
23
- | Flush(keys=["labels"])
24
- | RenameAttribute("output", "entities")
25
- )
26
-
27
- return pipeline
28
-
29
- tokenizer = AutoTokenizer.from_pretrained("knowledgator/UTC-DeBERTa-large-v2")
30
- model = AutoModelForTokenClassification.from_pretrained("knowledgator/UTC-DeBERTa-large-v2")
31
-
32
- transformers_pipeline = TokenClassificationPipeline(model=model, tokenizer=tokenizer, aggregation_strategy = 'first')
33
-
34
- if __name__=="__main__":
35
- pipeline = generate_pipeline()
36
- res = pipeline.run({
37
- "text": """Dr. Paul Hammond, a renowned neurologist at Johns Hopkins University, has recently published a paper in the prestigious journal "Nature Neuroscience".
38
- His research focuses on a rare genetic mutation, found in less than 0.01% of the population, that appears to prevent the development of Alzheimer's disease. Collaborating with researchers at the University of California, San Francisco, the team is now working to understand the mechanism by which this mutation confers its protective effect.
39
- Funded by the National Institutes of Health, their research could potentially open new avenues for Alzheimer's treatment."""
40
- })
41
-
42
  print(res)
 
1
+ from utca.core import RenameAttribute,Flush
2
+ from utca.implementation.predictors import TokenSearcherPredictor, TokenSearcherPredictorConfig
3
+ from utca.implementation.tasks import TokenSearcherNER, TokenSearcherNERPostprocessor
4
+ from utca.implementation.predictors.token_searcher.token_searcher_pipeline import TokenClassificationPipeline
5
+ from transformers import AutoTokenizer, AutoModelForTokenClassification
6
+
7
+ predictor = TokenSearcherPredictor(
8
+ TokenSearcherPredictorConfig(
9
+ model_name = "knowledgator/UTC-DeBERTa-large-v2",
10
+ device="cpu"
11
+ )
12
+ )
13
+
14
+ def generate_pipeline(threshold: float = 0.5):
15
+ ner_task = TokenSearcherNER(
16
+ predictor=predictor,
17
+ postprocess=TokenSearcherNERPostprocessor(
18
+ threshold=threshold
19
+ )
20
+ )
21
+ pipeline = (
22
+ ner_task
23
+ | Flush(keys=["labels"])
24
+ | RenameAttribute("output", "entities")
25
+ )
26
+
27
+ return pipeline
28
+
29
+ tokenizer = AutoTokenizer.from_pretrained("knowledgator/UTC-DeBERTa-large-v2")
30
+ model = AutoModelForTokenClassification.from_pretrained("knowledgator/UTC-DeBERTa-large-v2")
31
+
32
+ transformers_pipeline = TokenClassificationPipeline(device="cpu", model=model, tokenizer=tokenizer, aggregation_strategy = 'first')
33
+
34
+ if __name__=="__main__":
35
+ pipeline = generate_pipeline()
36
+ res = pipeline.run({
37
+ "text": """Dr. Paul Hammond, a renowned neurologist at Johns Hopkins University, has recently published a paper in the prestigious journal "Nature Neuroscience".
38
+ His research focuses on a rare genetic mutation, found in less than 0.01% of the population, that appears to prevent the development of Alzheimer's disease. Collaborating with researchers at the University of California, San Francisco, the team is now working to understand the mechanism by which this mutation confers its protective effect.
39
+ Funded by the National Institutes of Health, their research could potentially open new avenues for Alzheimer's treatment."""
40
+ })
41
+
42
  print(res)