https://github.com/fork123aniket/zero-shot-question-answering
  
  
    Implementation of Zero-Shot Question Answering in PyTorch 
    https://github.com/fork123aniket/zero-shot-question-answering
  
natural-language-processing nlp pytorch pytorch-tutorial question-answering transformers zero-shot-learning
        Last synced: 8 months ago 
        JSON representation
    
Implementation of Zero-Shot Question Answering in PyTorch
- Host: GitHub
 - URL: https://github.com/fork123aniket/zero-shot-question-answering
 - Owner: fork123aniket
 - License: mit
 - Created: 2022-09-28T15:23:12.000Z (about 3 years ago)
 - Default Branch: main
 - Last Pushed: 2022-10-18T10:29:32.000Z (about 3 years ago)
 - Last Synced: 2025-01-16T06:25:40.108Z (10 months ago)
 - Topics: natural-language-processing, nlp, pytorch, pytorch-tutorial, question-answering, transformers, zero-shot-learning
 - Language: Python
 - Homepage:
 - Size: 12.7 KB
 - Stars: 2
 - Watchers: 1
 - Forks: 0
 - Open Issues: 0
 - 
            Metadata Files:
            
- Readme: README.md
 - License: LICENSE
 
 
Awesome Lists containing this project
README
          # Zero-Shot Question Answering
This repository provides a simple code to implement zero-shot learning approach for Question Answering task. For each question `q` with available answer options `a`, `b`, and `c`, it computes each option's score as the negative log-likelihood under the language model conditioned on the question. More formally, score(a) = Pm(a|q); score(b) = Pm(b|q); and score(c) = Pm(c|q). It then returns the option with the highest score as the most probable answer to the question `q`.
## Setup Environment Requirements
- `PyTorch 1.11`
- `numpy 1.22.3`
- `transformers 4.16.2`
## Usage
The Question Answering model (***QAModel***) is defined inside `Zero_Shot_QA_Model.py` file. It loads the tokenizer and the language model in the initializer method. The `get_answer()` method goes over all available answer options for a given question and computes ***log-likelihood*** as the score for each option. It returns the option with the highest score. In addition to this, `Inference.py` file is also made available with a few examples of how this implementation is being used for Question Answering task in zero-shot manner.
## Results
```
- Question: Where is capital of France?
  Available Options: London, Berlin, Paris, Lyon
  Predicted Answer: Paris
- Question: Who is best known for developing the theory of relativity?
  Available Options: Albert Einstein, Isaac Newton, Stephen Hawking, Max Planck
  Predicted Answer: Albert Einstein
  
- Question: Who is CEO of Tesla?
  Available Options: Bill Gates, Elon Musk, Steve Jobs, Tim cook
  Predicted Answer: Elon Musk
```