Giter VIP home page Giter VIP logo

optok's Introduction

Optimizing Word Segmentation for Downstream Task

Author's implementation of "Optimizing Word Segmentation for Downstream Task". In short, we call our system "OpTok: Optimizing Tokenization".

FYI: We extended OpTok to be used for various NLP tasks in "Joint Optimization of Tokenization and Downstream Model" and you can access the official implementation.

Requirements

  • multigram v0.1
  • numpy==1.18.0
  • torch==1.6.0+cu101
  • (transformers==2.8.0, if you use BERT as an encoder)

Setup

Install multigram v0.1 and prepare OpTok repository.

$ mkdir optok_environment
$ cd optok_environment
$ git clone https://github.com/tatHi/multigram -b v0.1
$ git clone https://github.com/tatHi/optok
$ cd multigram
$ pip install --editable .

Run exapmle

/src/run_example.py describes example codes of training OpTok, dumping models, and tokenize text with a trained language model.

$ cd optok/src
$ mkdir test_dir
$ python run_example.py
>>> BUILD VOCABULARY
possible n-grams (n=5): 9
>>> INITIALIZE THETA
------------------------------
Predicted scores
tensor([[0.6488, 0.8476],
        [0.6342, 0.7852],
        [0.5614, 0.4838]], grad_fn=<AddmmBackward>)
------------------------------
Classification loss
tensor(0.7169, grad_fn=<NllLossBackward>)
------------------------------
Language model loss
tensor(0.1875, grad_fn=<DivBackward0>)
------------------------------
>>> DUMP LEARNED LM AS MLM
Tokenization
------------------------------
pieces: ['a', 'b', 'cd', 'e', 'f', 'g']
ids   : [1, 2, 4, 6, 7, 8]
------------------------------
pieces: ['cd', 'a', 'b', 'c', 'cd']
ids   : [4, 1, 2, 3, 4]
------------------------------
pieces: ['a', 'b', 'b', 'cd', 'e']
ids   : [1, 2, 2, 4, 6]
------------------------------

Experimental Settings

Training split of Amazon Dataset and Twitter(Ja) dataset used in the paper is available here. The google drive also includes pre-trained word embeddings and SentencePiece model for each experiment.

optok's People

Contributors

tathi avatar

Stargazers

Hayato Tsukagoshi avatar seiichi avatar Takuya Makino avatar Junki Ohmura avatar Hitoshi Manabe avatar Alex Nguyen avatar Abdullah Mohammed avatar Peter Baylies avatar  avatar  avatar himkt 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.