[PYTHON] BERT fordert Quiz Schulter Tackle

Einführung

Schauen Sie sich das bitte zuerst an. Quizshow https://www.youtube.com/watch?v=m50H_0B78aQ&feature=emb_logo

Betriebsumgebung

Überprüfungsinhalt

Implementierungsdetails

  1. Was ist die aktuelle Hauptstadt von Japan?

Quellcode (nur Fragenbereich)

python


questions = [
    'Where is the capital of Japan?',
    'Where is the capital of the United States of America?',
    'Where is the capital of France?',
    'Would you like something to drink?',
    'Where is the capital of the United Kingdom?',
    'Where is the capital of Republic of Botswana?',
    'Where is the capital of Australia?',
    'Roise or Noise?'
]

reader = DocumentReader("deepset/bert-base-cased-squad2") 

# if you trained your own model using the training cell earlier, you can access it with this:
#reader = DocumentReader("./models/bert/bbu_squad2")


for question in questions:
    answer = ""
    print(f"Question: {question}")
    results = wiki.search(question)

    for result in results:
      try:
        #page = wiki.page(results[0])
        page = wiki.page(result)
        #print(f"Top wiki result: {page}")

        text = page.content

        reader.tokenize(question, text)
      except:
        print('PageError ocurred! Searching another page..')

      answer = reader.get_answer()
      if len(answer) >0:
        print(f"Answer: {answer}\n")
        break
      else:
        print("...")

Ausführungsergebnis

Beginnen wir jetzt mit dem Quiz-Schulter-Tackle.

Question: Where is the capital of Japan?
...
Answer: Tokyo / Heian - kyō ( modern Kyoto ) / Tokyo / Tokyo / 

Das ist die richtige Antwort. Ich hätte auch nicht gedacht, dass Heiankyo die Antwort finden würde.

Question: Where is the capital of the United States of America?
...
Answer: Washington , D . C . / The District of Columbia / 

Ist die richtige Antwort.

Question: Where is the capital of France?
Answer: Saint - Denis / Paris / [CLS] Where is the capital of France ? [SEP]toile , while the working - class neighbourhood of the Faubourg Saint - Antoine on the eastern site of the city grew more and more crowded with poor migrant workers from other regions of France . Paris was the centre of an explosion of philosophic and scientific activity known as the Age of Enlightenment . Diderot and d ' Alembert published their Encyclopédie in 1751 , and the Montgolfier Brothers launched the first manned flight in a hot - air balloon on 21 November 1783 , from the gardens of the Château de la Muette . Paris was the financial capital of continental Europe / Paris / Paris / Paris ' 16th arrondissement / 

Ich wurde gebeten, es zusammenzufalten. Du hast Saint-Doni geantwortet. Ist es △, der Paris überhaupt beantwortet hat?

Question: Would you like something to drink?
Answer: juice or soda / 

Ja, bitte trink.

Question: Where is the capital of the United Kingdom?
...
Answer: London / London / Edinburgh / 

Ist die richtige Antwort.

Question: Where is the capital of Republic of Botswana?
Answer: Gaborone / Gaborone / 

Es ist eine schwierige Frage, aber es ist die richtige Antwort.

Question: Where is the capital of Australia?
Answer: Canberra / Canberra / Canberra / 

Dies ist auch die richtige Antwort.

Question: Noice or Roice?
...

Ich habe geschwiegen. Wikipedia hat möglicherweise keine Antwort auf die schicksalsverändernde Frage.

Zusammenfassung

Schließlich wusste ich nicht, wie viele Punkte ich gesammelt hatte, also lassen wir den 10-Millionen-Yen-Typ nächste Woche wieder.

Referenzlink

Ich durfte mich beziehen. Vielen Dank. Building a QA System with BERT on Wikipedia Chocolate Planet Channel

Recommended Posts

BERT fordert Quiz Schulter Tackle