Upload folder using huggingface_hub
Browse files- __pycache__/tfidf.cpython-311.pyc +0 -0
- main/QBModelConfig.py +11 -0
- main/QBModelWrapperCopy.py +20 -0
- main/QBpipeline.py +60 -0
- main/config.json +23 -0
- main/pytorch_model.bin +3 -0
- resources/.DS_Store +0 -0
- test-huggingface +1 -0
- tfidf.py +0 -2
__pycache__/tfidf.cpython-311.pyc
CHANGED
Binary files a/__pycache__/tfidf.cpython-311.pyc and b/__pycache__/tfidf.cpython-311.pyc differ
|
|
main/QBModelConfig.py
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import PretrainedConfig
|
2 |
+
import torch
|
3 |
+
|
4 |
+
class QBModelConfig(PretrainedConfig):
|
5 |
+
model_type = 'QA-umd-quizbowl'
|
6 |
+
|
7 |
+
def __init__(self, **kwargs):
|
8 |
+
self.torch_dtype = torch.float16
|
9 |
+
super().__init__( **kwargs)
|
10 |
+
|
11 |
+
|
main/QBModelWrapperCopy.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import List
|
2 |
+
from transformers import PreTrainedModel
|
3 |
+
from transformers import PretrainedConfig
|
4 |
+
from QBModelConfig import QBModelConfig
|
5 |
+
from qbmodel import QuizBowlModel
|
6 |
+
|
7 |
+
class QBModelWrapper(PreTrainedModel):
|
8 |
+
config_class= QBModelConfig
|
9 |
+
|
10 |
+
|
11 |
+
def __init__(self, config):
|
12 |
+
super().__init__(config)
|
13 |
+
|
14 |
+
self.model = QuizBowlModel()
|
15 |
+
self.tfmodel = self.model.guesser
|
16 |
+
|
17 |
+
|
18 |
+
def forward(self, question, context):
|
19 |
+
output = self.model.guess_and_buzz([question])
|
20 |
+
return output[0]
|
main/QBpipeline.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import Pipeline
|
2 |
+
from transformers.utils import ModelOutput
|
3 |
+
|
4 |
+
from transformers import PreTrainedModel, Pipeline
|
5 |
+
from typing import Any, Dict, List
|
6 |
+
|
7 |
+
class QApipeline(Pipeline):
|
8 |
+
def __init__(
|
9 |
+
self,
|
10 |
+
model: PreTrainedModel,
|
11 |
+
**kwargs
|
12 |
+
):
|
13 |
+
super().__init__(
|
14 |
+
model=model,
|
15 |
+
**kwargs
|
16 |
+
)
|
17 |
+
|
18 |
+
print("in __init__")
|
19 |
+
|
20 |
+
def __call__( self, question: str, context: str, **kwargs) -> Dict[str, Any]:
|
21 |
+
inputs = {
|
22 |
+
"question": question,
|
23 |
+
"context": context
|
24 |
+
}
|
25 |
+
|
26 |
+
outputs = self.model(**inputs)
|
27 |
+
|
28 |
+
answer = self._process_output(outputs)
|
29 |
+
|
30 |
+
print("in __call___")
|
31 |
+
|
32 |
+
return {"answer": answer}
|
33 |
+
|
34 |
+
def _process_output(self, outputs: Any) -> str:
|
35 |
+
|
36 |
+
print("in process outputs")
|
37 |
+
|
38 |
+
format = {'guess': outputs[0], 'confidence': int(outputs[1])}
|
39 |
+
return format
|
40 |
+
|
41 |
+
|
42 |
+
def _sanitize_parameters(self, **kwargs):
|
43 |
+
print("in sanatize params")
|
44 |
+
|
45 |
+
return {}, {}, {}
|
46 |
+
|
47 |
+
def preprocess(self, inputs):
|
48 |
+
print("in preprocess")
|
49 |
+
|
50 |
+
return inputs
|
51 |
+
|
52 |
+
def postprocess(self, outputs):
|
53 |
+
print("in postprocess")
|
54 |
+
format = {'guess': outputs[0], 'confidence': float(outputs[1])}
|
55 |
+
return format
|
56 |
+
|
57 |
+
def _forward(self, input_tensors, **forward_parameters: Dict) -> ModelOutput:
|
58 |
+
print("in _forward")
|
59 |
+
return super()._forward(input_tensors, **forward_parameters)
|
60 |
+
|
main/config.json
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"QBModelWrapper"
|
4 |
+
],
|
5 |
+
"auto_map": {
|
6 |
+
"AutoConfig": "QBModelConfig.QBModelConfig",
|
7 |
+
"AutoModelForQuestionAnswering": "QBModelWrapperCopy.QBModelWrapper"
|
8 |
+
},
|
9 |
+
"custom_pipelines": {
|
10 |
+
"qa-pipeline-qb": {
|
11 |
+
"impl": "QBpipeline.QApipeline",
|
12 |
+
"pt": [
|
13 |
+
"AutoModelForQuestionAnswering"
|
14 |
+
],
|
15 |
+
"tf": [
|
16 |
+
"TFAutoModelForQuestionAnswering"
|
17 |
+
]
|
18 |
+
}
|
19 |
+
},
|
20 |
+
"model_type": "QA-umd-quizbowl",
|
21 |
+
"torch_dtype": "float16",
|
22 |
+
"transformers_version": "4.40.1"
|
23 |
+
}
|
main/pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c4c64ac2a95e8002d6b3f02bc84e6dc4e980d5e592e6ad7897361ed2ad1462e0
|
3 |
+
size 888
|
resources/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
test-huggingface
CHANGED
@@ -37,6 +37,7 @@ PIPELINE_REGISTRY.register_pipeline(
|
|
37 |
|
38 |
qa_pipe = pipeline("qa-pipeline-qb", model=qb_model)
|
39 |
#qa_pipe.push_to_hub("new-attempt-pipeline-2", safe_serialization=False)
|
|
|
40 |
|
41 |
result = qa_pipe(question="This star in the solar system has 8 planets", context="Context for the question")
|
42 |
print(result["answer"])
|
|
|
37 |
|
38 |
qa_pipe = pipeline("qa-pipeline-qb", model=qb_model)
|
39 |
#qa_pipe.push_to_hub("new-attempt-pipeline-2", safe_serialization=False)
|
40 |
+
qa_pipe.save_pretrained("main", safe_serialization=False)
|
41 |
|
42 |
result = qa_pipe(question="This star in the solar system has 8 planets", context="Context for the question")
|
43 |
print(result["answer"])
|
tfidf.py
CHANGED
@@ -8,7 +8,6 @@ import os
|
|
8 |
from nltk.corpus import stopwords
|
9 |
from nltk.tokenize import word_tokenize
|
10 |
from nltk.stem import WordNetLemmatizer
|
11 |
-
from models import processed_tfidf_wiki_page_text_model
|
12 |
|
13 |
|
14 |
class TfidfWikiGuesser:
|
@@ -18,7 +17,6 @@ class TfidfWikiGuesser:
|
|
18 |
self.titles = None
|
19 |
self.vectorizer = None
|
20 |
self.lemmatizer = WordNetLemmatizer()
|
21 |
-
mod_file = processed_tfidf_wiki_page_text_model
|
22 |
model_file = "processed_tfidf_wiki_page_text_model.pkl" # <--- has best acc so far (using wiki_page_text.json from gdrive folder)
|
23 |
#model_file = "processed_tfidf_wiki_16_model.pkl"
|
24 |
# full_model_path = model_file
|
|
|
8 |
from nltk.corpus import stopwords
|
9 |
from nltk.tokenize import word_tokenize
|
10 |
from nltk.stem import WordNetLemmatizer
|
|
|
11 |
|
12 |
|
13 |
class TfidfWikiGuesser:
|
|
|
17 |
self.titles = None
|
18 |
self.vectorizer = None
|
19 |
self.lemmatizer = WordNetLemmatizer()
|
|
|
20 |
model_file = "processed_tfidf_wiki_page_text_model.pkl" # <--- has best acc so far (using wiki_page_text.json from gdrive folder)
|
21 |
#model_file = "processed_tfidf_wiki_16_model.pkl"
|
22 |
# full_model_path = model_file
|