forked from saxenabhishek/nobook.learn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_nlp.py
56 lines (37 loc) · 1.71 KB
/
main_nlp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from src.transformerswrapper import CustomTransformer
customtrans = CustomTransformer()
def question_answers(text: str):
"""
This function returns a list with dictionary which has questions and answers
"""
main_dict = {}
questionList = []
contents = customtrans.questionGeneration(context=text)
return contents
def checkanswers(userAns: str, originalAns: str, metric: int):
"""
returns a boolenn value
"""
uservec = customtrans.siamese(userAns, max_length=128)
originalvec = customtrans.siamese(originalAns, max_length=128)
distance = customtrans.distance(uservec, originalvec)
print(distance)
if distance > metric:
return False
return True
def simpler_question_answers(text: str, max_length: int, min_length: int):
"""
simplifies the paragraph and generates questions and answer on the simplified text
"""
easytext = customtrans.summerizer(text, max_length=max_length, min_length=min_length)
return easytext[0]["summary_text"]
def generateText(text: str, max_length: int):
return customtrans.generateText(text, max_length=max_length)
if __name__ == "__main__":
text1 = """
The physical nature of time is addressed by general relativity with respect to events in space-time.
Examples of events are the collision or two particles, the explosion of a supernova, or the arrival of a rocket ship.
Every event can be assigned four numbers representing its time and position (the event's coordinates).
However, the numerical values are different for different observers.
"""
print(checkanswers("physical nature of time is addressed by general ", "physical time is addressed by your mom", 7))