Code Monkey home page Code Monkey logo

minilm-v2's Introduction

Unofficial Implementation of MiniLM-v2

This is an unofficial implementation of MiniLM-v2 using Huggingface Transformers, PyTorch and PyTorch Lightning. Currently, only BERT architectures are supported.

Data

To distill a model, you first need to pretokenize your data. This repository expects a gzipped jsonl file containing lists of tokenized sentences. See test/test_text.jsonl.gz for an example. You can use the minilm_v2/data.py script to pretokenize your data.

$ python minilm_v2/data.py -h
usage: data.py [-h] --text_files TEXT_FILES [TEXT_FILES ...] --save_path SAVE_PATH --tokenizer_name TOKENIZER_NAME
               [--batch_size BATCH_SIZE] [--num_lines]

Tokenizes text files and writes the token ids to a pickle file. Each line in a text file is considered as a new sample.
Optionally splits the input by sentences.

options:
  -h, --help            show this help message and exit
  --text_files TEXT_FILES [TEXT_FILES ...]
                        Text file paths to tokenize
  --save_path SAVE_PATH
                        Path to save the pickled token ids to
  --tokenizer_name TOKENIZER_NAME
                        Name of or path to local huggingface tokenizer
  --batch_size BATCH_SIZE
                        Number of lines to tokenize at once.
  --num_lines           Count number of lines before tokenizing. Useful for estimating ETA.

Distilling a Model

Next, you need to write a huggingface config.json file specifying the model architecture you want to distill to. See configs/lh-h384/config.json for an example. Then, modifiy the fit.yaml configuration file. It contains all model, data, training and logging parameters. Note that the student path should be the path of the directory containing the config.json file. See the Lightning CLI for details more information on all options. To start training, run python minilm_v2/fit.py fit.yaml.

NOTE: At the end of training, the model is saved in the directory of the architecture config.json file.

References

https://github.com/microsoft/unilm/tree/master/minilm https://arxiv.org/abs/2012.15828

minilm-v2's People

Contributors

fschlatt avatar

Watchers

 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.