nes470 commited on
Commit
1a383f7
verified
1 Parent(s): 48d4868

Update qbmodel.py

Browse files
Files changed (1) hide show
  1. qbmodel.py +52 -52
qbmodel.py CHANGED
@@ -1,52 +1,52 @@
1
- from typing import List, Tuple
2
- import nltk
3
- import sklearn
4
- from project.tfidf import TfidfWikiGuesser
5
- import numpy as np
6
- import pandas as pd
7
-
8
-
9
- class QuizBowlModel:
10
-
11
- def __init__(self):
12
- """
13
- Load your model(s) and whatever else you need in this function.
14
-
15
- Do NOT load your model or resources in the guess_and_buzz() function,
16
- as it will increase latency severely.
17
- """
18
-
19
- self.guesser = TfidfWikiGuesser() #can specify different wikidump if needed
20
- print("model loaded")
21
-
22
-
23
-
24
- def guess_and_buzz(self, question_text: List[str]) -> List[Tuple[str, bool]]:
25
- """
26
- This function accepts a list of question strings, and returns a list of tuples containing
27
- strings representing the guess and corresponding booleans representing
28
- whether or not to buzz.
29
-
30
- So, guess_and_buzz(["This is a question"]) should return [("answer", False)]
31
-
32
- If you are using a deep learning model, try to use batched prediction instead of
33
- iterating using a for loop.
34
- """
35
-
36
- answers = []
37
- top_guesses = 3 #guesser will return this amount guesses for each question (in sorted confidence)
38
-
39
- for question in question_text:
40
- guesses = self.guesser.make_guess(question, num_guesses=top_guesses)
41
- #print(guesses)
42
-
43
- #do the buzzing
44
-
45
- #make a tuple and add to answers list
46
- tup = (guesses[0], True)
47
- answers.append(tup)
48
-
49
- return answers
50
-
51
-
52
-
 
1
+ from typing import List, Tuple
2
+ import nltk
3
+ import sklearn
4
+ from tfidf import TfidfWikiGuesser
5
+ import numpy as np
6
+ import pandas as pd
7
+
8
+
9
+ class QuizBowlModel:
10
+
11
+ def __init__(self):
12
+ """
13
+ Load your model(s) and whatever else you need in this function.
14
+
15
+ Do NOT load your model or resources in the guess_and_buzz() function,
16
+ as it will increase latency severely.
17
+ """
18
+
19
+ self.guesser = TfidfWikiGuesser() #can specify different wikidump if needed
20
+ print("model loaded")
21
+
22
+
23
+
24
+ def guess_and_buzz(self, question_text: List[str]) -> List[Tuple[str, bool]]:
25
+ """
26
+ This function accepts a list of question strings, and returns a list of tuples containing
27
+ strings representing the guess and corresponding booleans representing
28
+ whether or not to buzz.
29
+
30
+ So, guess_and_buzz(["This is a question"]) should return [("answer", False)]
31
+
32
+ If you are using a deep learning model, try to use batched prediction instead of
33
+ iterating using a for loop.
34
+ """
35
+
36
+ answers = []
37
+ top_guesses = 3 #guesser will return this amount guesses for each question (in sorted confidence)
38
+
39
+ for question in question_text:
40
+ guesses = self.guesser.make_guess(question, num_guesses=top_guesses)
41
+ #print(guesses)
42
+
43
+ #do the buzzing
44
+
45
+ #make a tuple and add to answers list
46
+ tup = (guesses[0], True)
47
+ answers.append(tup)
48
+
49
+ return answers
50
+
51
+
52
+