Giter Club home page Giter Club logo

langmodel's Introduction

langmodel

Simple implementation of a word-based language model that learns to predict the next word based on the previous one by training on a provided text dataset (Karpathy's Tiny Shakespeare in this case). This model is a rudimentary form of a language model and does not include complex features like embeddings, LSTMs or attention mechanisms found in modern language models. Instead, it provides a simple demonstration of how a language model can be implemented using a transition matrix to capture statistical patterns in the text data.

How it works:

  1. Text data loaded from a file, preprocessed (converting it to lowercase and tokenizing it into words).
  2. Input-Output pairs are created from the text data for training the language model.
  3. A simple word based language model is defined with a transition matrix representing the probabilities of transitioning from one word to another.
  4. The model is trained on the training data.
  5. Text generation is performed by predicting the next word based on the current word using the trained model.

Compute perplexity for the language model. It is a level of "certanty" of the Model and is calculated as the inverse probability of the test set normalized by the number of words. In this file it is being computed this way:

  1. Iterating over the test data;
  2. Computing the probability of each word given the preceding words;
  3. Accumulating the log probability;
  4. Final reuslt is calculated by exponentiating the negative log probability divided by the number of words.

Other way to compute perplexity is 2^(average bits per word) for a given test text set. Perplexity of 1 will mean that we don't need to predict the word because its known

langmodel's People

Contributors

lexiestleszek avatar

Stargazers

 avatar

Watchers

Kostas Georgiou avatar  avatar

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.