Update handler.py
Browse files- handler.py +11 -7
handler.py
CHANGED
@@ -3,9 +3,9 @@ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, pipeline
|
|
3 |
import torch
|
4 |
|
5 |
class EndpointHandler:
|
6 |
-
def __init__(self, path=""):
|
7 |
# Load model and processor from path
|
8 |
-
self.model = AutoModelForSeq2SeqLM.from_pretrained(path
|
9 |
self.tokenizer = AutoTokenizer.from_pretrained(path)
|
10 |
|
11 |
def __call__(self, data: Dict[str, Any]) -> Dict[str, str]:
|
@@ -24,11 +24,15 @@ class EndpointHandler:
|
|
24 |
# Modify parameters to increase max_length
|
25 |
if parameters is None:
|
26 |
parameters = {}
|
27 |
-
parameters['max_length'] =
|
28 |
-
parameters['min_length'] =
|
29 |
-
parameters['length_penalty'] = 2.0
|
30 |
-
parameters['num_beams'] =
|
31 |
-
parameters['early_stopping'] = True
|
|
|
|
|
|
|
|
|
32 |
|
33 |
|
34 |
# Generate output
|
|
|
3 |
import torch
|
4 |
|
5 |
class EndpointHandler:
|
6 |
+
def __init__(self, path="atwine/translation-en-lug-v6"):
|
7 |
# Load model and processor from path
|
8 |
+
self.model = AutoModelForSeq2SeqLM.from_pretrained(path)
|
9 |
self.tokenizer = AutoTokenizer.from_pretrained(path)
|
10 |
|
11 |
def __call__(self, data: Dict[str, Any]) -> Dict[str, str]:
|
|
|
24 |
# Modify parameters to increase max_length
|
25 |
if parameters is None:
|
26 |
parameters = {}
|
27 |
+
parameters['max_length'] = 512 # Set your desired max_length here
|
28 |
+
parameters['min_length'] = 100
|
29 |
+
parameters['length_penalty'] = 2.0
|
30 |
+
parameters['num_beams'] = 10
|
31 |
+
parameters['early_stopping'] = True
|
32 |
+
parameters['temperature'] = 0.0
|
33 |
+
parameters['top_k'] = 15
|
34 |
+
parameters['top_p'] = 0.8
|
35 |
+
|
36 |
|
37 |
|
38 |
# Generate output
|