vincentclaes commited on
Commit
1629f42
β€’
1 Parent(s): a226e89

question answering text

Browse files
Files changed (4) hide show
  1. Pipfile +0 -14
  2. Pipfile.lock +0 -0
  3. README.md +1 -1
  4. app.py +58 -11
Pipfile DELETED
@@ -1,14 +0,0 @@
1
- [[source]]
2
- url = "https://pypi.org/simple"
3
- verify_ssl = true
4
- name = "pypi"
5
-
6
- [packages]
7
- transformers = "*"
8
- gradio = "*"
9
-
10
- [dev-packages]
11
-
12
- [requires]
13
- python_version = "3.9"
14
- python_full_version = "3.9.13"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Pipfile.lock DELETED
The diff for this file is too large to render. See raw diff
 
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Vacancy Keyword Extraction
3
  emoji: πŸš€
4
  colorFrom: blue
5
  colorTo: white
 
1
  ---
2
+ title: Question Answer Text
3
  emoji: πŸš€
4
  colorFrom: blue
5
  colorTo: white
app.py CHANGED
@@ -1,17 +1,64 @@
1
  import gradio as gr
2
- from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
3
- title = "Vacancy Keyword Extraction"
4
- description = "Add a vacancy and ask what keyword you would like to retrieve. For example, What is the job title? What is the city? What is the start date?"
5
 
 
 
6
 
7
- classifier = pipeline("question-answering", model="deepset/roberta-base-squad2", model_max_length=512)
8
 
9
- def zeroShotClassification(text_input, question):
10
- prediction = classifier(context=text_input, question=question, truncation=True, max_length="max_length", padding=True)
 
 
 
 
 
 
 
 
 
 
 
11
  return f'{prediction["answer"]}'
12
 
13
- gr.Interface(fn=zeroShotClassification,
14
- inputs=[gr.inputs.Textbox(lines=10, label="Vacancy", placeholder="Paste the context of a vacancy."),
15
- gr.inputs.Textbox(lines=2, label="Question", placeholder="Ask what you want to retrieve from the vacancy.")],
16
- outputs=gr.outputs.Textbox(label="Answer"),
17
- title=title, description=description).launch(share=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
 
 
3
 
4
+ title = "Question Answer on Text"
5
+ description = "Provide a piece of text, ask a question and get a meaningful answer."
6
 
 
7
 
8
+ classifier = pipeline(
9
+ "question-answering", model="deepset/roberta-base-squad2", model_max_length=512
10
+ )
11
+
12
+
13
+ def zero_shot_classification(text_input, question):
14
+ prediction = classifier(
15
+ context=text_input,
16
+ question=question,
17
+ truncation=True,
18
+ max_length="max_length",
19
+ padding=True,
20
+ )
21
  return f'{prediction["answer"]}'
22
 
23
+
24
+ examples = [
25
+ [
26
+ """The invoice contains all the goods that are described in the order with number x9820be.
27
+ The goods are packaged and should arrive at the destination on 31/12/2023.
28
+ We kindly request to transfer the amount within 30 days of the invoice date to the account number BE00 9999 9999 9999""",
29
+ "what is the timeline to transfer the money?",
30
+ ],
31
+ [
32
+ """The invoice contains all the goods that are described in the order with number x9820be.
33
+ The goods are packaged and should arrive at the destination on 31/12/2023.
34
+ We kindly request to transfer the amount within 30 days of the invoice date to the account number BE00 9999 9999 9999""",
35
+ "what is the account number to transfer the money?",
36
+ ],[
37
+ """The invoice contains all the goods that are described in the order with number x9820be.
38
+ The goods are packaged and should arrive at the destination on 31/12/2023.
39
+ We kindly request to transfer the amount within 30 days of the invoice date to the account number BE00 9999 9999 9999""",
40
+ "order number",
41
+ ],
42
+ [
43
+ """By signing below, Shipper hereby declares that the contents of this consignment are fully and accurately described above by the proper shipping name and are classified,
44
+ packaged, marked and labelled/placarded, and are in all respects in proper condition for transport according to applicable governmental regulations. As shipper, I hereby
45
+ certify that the liquid industrial by-product(s) are fully and accurately described on this shipping document, in proper condition for transport, and that the information
46
+ contained on the shipping document is factual.""",
47
+ "are the goods described?",
48
+ ],
49
+ ]
50
+
51
+ gr.Interface(
52
+ fn=zero_shot_classification,
53
+ inputs=[
54
+ gr.inputs.Textbox(lines=10, label="Text", placeholder="Paste text here ..."),
55
+ gr.inputs.Textbox(
56
+ lines=2,
57
+ label="Question",
58
+ placeholder="Ask what you want to retrieve from the vacancy.",
59
+ ),
60
+ ],
61
+ outputs=gr.outputs.Textbox(label="Answer"),
62
+ title=title,
63
+ description=description,
64
+ ).launch(share=False)