Giter Club home page Giter Club logo

bertml's Introduction

bertml

High-level non-blocking Deno bindings to the rust-bert machine learning crate.

Guide

Introduction

The ModelManager class manages the FFI bindings and all of your models that connect to the bindings. You create models from the manager and then use the methods on those classes. The creation of a ModelManager is synchronous as the loading of binaries with the Deno FFI API is synchronous. Therefore, make sure you create your ModelManager before asynchronous logic begins to not cause any unexpected behavior.

const manager = await ModelManager.create();

Creating Models

To create models, simply call the corresponding create*Model method on the ModelManager class and store the model as a variable. For this example, we'll be creating a question answering model:

const manager = await ModelManager.create();

const qaModel = await manager.createQAModel();

const answers = await qaModel.query({
  questionGroups: [
    {
      context: "Amy lives in Canada.",
      question: "Where does Amy live?",
    },
  ],
});

console.log(answers);

Output:

[ [ { score: 0.985611081123352, start: 13, end: 19, answer: "Canada" } ] ]

If you need to learn more about creating instances of models, then simply check out the docs.

Supported Pipelines

Note: we do not currently support any model-level configuration except for the different languages for the TranslationModel.

  • SummarizationModel
  • ConversationModel
  • TranslationModel
  • NERModel
  • QAModel
  • SentimentModel
  • POSModel
  • ZeroShotClassificationModel
  • TextGenerationModel

To test out these pipelines, you can try and run the dev.ts file. However, this will automatically install the necessary models so I advise you comment out the models you don't want to download.

@inproceedings{becquin-2020-end,
    title = "End-to-end {NLP} Pipelines in Rust",
    author = "Becquin, Guillaume",
    booktitle = "Proceedings of Second Workshop for NLP Open Source Software (NLP-OSS)",
    year = "2020",
    publisher = "Association for Computational Linguistics",
    url = "https://www.aclweb.org/anthology/2020.nlposs-1.4",
    pages = "20--25",
}

Acknowledgements

rust-bert loads the models from Hugging Face and bertml also has a huge thanks to Hugging Face for making these models public and interfaceable with Rust (+ Deno).

License

MIT

bertml's People

Contributors

sno2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ochanje210

bertml's Issues

`TypeError: Deno.dlopen is not a function`

Hello,

I am trying to use the sentiment model, but I get an error. This is my code:

const manager = await ModelManager.create();
const sentimentModel = await manager.createSentimentModel();

async function filterTweets(tweets: TwitterResponse) {
    const sentiments = await sentimentModel.predict(tweets.data.map(tweet => tweet.text));
    return tweets.data.filter((_, index) => {
        return sentiments[index].score > 0.7;
    });
}

Error

at Module.prepare (https://deno.land/x/[email protected]/plug.ts:77:15)
  at async Function.create (https://deno.land/x/[email protected]/model_manager.ts:181:17)

Command

bash deno run -A ./src/tweets.ts --unstable

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.