Skip to main content

Mbedder: A pytorch powered framework for seemlessly adding contextual text embeddings from pretrained models

Project description


Mbedder is a language framework for adding contextual embeddings of pretrained language models to deep learning models.Mbedder is powered by PyTorch and HuggingFace and requires as less as 1 line of code to add embeddings and works similar to how the Embedding Layer works in PyTorch.

List of supported architectures

  • Bert
  • XLNet
  • Albert
  • TransfoXL
  • DistilBert
  • Roberta
  • XLM
  • XLMRoberta
  • GPT
  • GPT2
  • Flaubert

The pretrained models for the mentioned architecures can be found here.

Features

  • Addition of embeddings with 1 line of code
  • Embeddings can output Sentence as well as Token level embeddings
  • Task specific combination strategies can be applied to hidden states and token embeddings
  • Custom pre-trained hugging face transformer models can be used with Mbedder.

Requirements and Installation

  • PyTorch version >= 1.6.0
  • Python version >= 3.6
  • Transformer >= 3.0.2

Mbedder can be using Pip as follows

pip install Mbedder

Getting Started

A basic example of using a Mbedder Bert embedding is shown below:

import torch
from Mbedder import BertEmbedding

class BertClassifier(torch.nn.Module):
    def __init__(self, num_classes):
        super(BertClassifier, self).__init__()
        self.embedding = BertEmbedding.from_pretrained('bert-base-uncased')
        self.fc = torch.nn.Linear(self.embedding.embedding_size, num_classes)
    
    def forward(self, input_ids, attention_mask):
        x = self.embedding(input_ids, attention_mask, output_token_embeddings=False)
        logits = self.fc(x[0])
        return logits

More advanced examples can be found in the examples folder.

License

Mbedder is MIT-licensed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Mbedder-0.0.4.tar.gz (5.9 kB view details)

Uploaded Source

File details

Details for the file Mbedder-0.0.4.tar.gz.

File metadata

  • Download URL: Mbedder-0.0.4.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.2

File hashes

Hashes for Mbedder-0.0.4.tar.gz
Algorithm Hash digest
SHA256 aee1dc6279840ed08723c62ef842a573b2cf3868e11f44105005af29dc03721f
MD5 3416462db7c64fd00452c11253f96299
BLAKE2b-256 b12513c88b8d9187a87619be9511468b04f4a6046fc9df3d8447205c59a031d5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page