Giter Site home page Giter Site logo

a7madkaddour / bidaf Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 9.75 MB

Implementation of the Bi-Directional Attention Flow Model (BiDAF) in Python using Keras

Python 100.00%
bidaf attention-mechanism nlp python keras question-answering bidirectional-lstm deep-learning neural-networks machine-comprehension natural-language-processing squad glove word-embeddings

bidaf's Introduction

BiDAF

Implementation of the Bi-Directional Attention Flow Model (BiDAF) in Python using Keras

Usage

You can use the provided functionality to train, predict and evaluate your custom versions of the model, by tuning the model's hyperparameters in very simple ways.

  • Setup

    • Initializing The Model:

      from BiDAF import BiDAFModel
      
      max_context_length = 150
      max_query_length = 15
      emdim = 100
      
      model = BiDAFModel(d=emdim, max_context_lenght=max_context_length,
                         max_question_lenght=max_query_length, dropout=0.4, learning_rate=0.05)
    • Preparing The Data:

      from data_generation import get_train_data, get_validation_data
      
      X_train, X_test, y_train, y_test = get_train_data(max_context_length, max_query_length)
      validation_data = get_validation_data(max_context_length, max_query_length)
  • Training

    model.run_training(X_train, y_train,
                       epochs=100, validation_data=validation_data, batch_size=64)  
  • Evaluation

    • Model Evaluation:

      model.evaluate(X_test, y_test) 
    • F1 and Exact Match Evaluation:

      from preprocess import parse_and_save_data, get_json_data
      from evaluation import get_raw_scores, make_eval_dict
      import pandas as pd
      
      json_data = get_json_data('dev')
      
      formated_data_path = parse_and_save_data('dev', 'dev_data')
      data_frame = pd.read_csv(formated_data_path)
      
      contexts = data_frame['context'].to_list()
      questions = data_frame['question'].to_list()
      qids = data_frame['qid'].to_list()
      
      predections_list = model.predict(contexts, questions, qids)
      predections_dict = {answer_dict['id']: answer_dict['answer'] for answer_dict in predections_list}
      
      em, f1 = get_raw_scores(json_data, predections_dict)
      eval_dict = make_eval_dict(em, f1, qids)
      
      print(eval_dict)
  • Prediction

    context = "The Normans (Norman: Nourmands; French: Normands; Latin: Normanni) were the people who in the 10th and 11th centuries gave their name to Normandy, a region in France. They were descended from Norse ("Norman" comes from "Norseman") raiders and pirates from Denmark, Iceland and Norway who, under their leader Rollo, agreed to swear fealty to King Charles III of West Francia. Through generations of assimilation and mixing with the native Frankish and Roman-Gaulish populations, their descendants would gradually merge with the Carolingian-based cultures of West Francia. The distinct cultural and ethnic identity of the Normans emerged initially in the first half of the 10th century, and it continued to evolve over the succeeding centuries."
    
    question = "In what country is Normandy located?"
    
    model.predict(context, question)

bidaf's People

Contributors

a7madkaddour avatar

Watchers

 avatar

bidaf's Issues

Tf Version

Which tensorflow version did you use?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.