All Projects → davidalami → ConveRT

davidalami / ConveRT

Licence: Apache-2.0 license
Dual Encoders for State-of-the-art Natural Language Processing.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to ConveRT

wikiHow paper list
A paper list of research conducted based on wikiHow
Stars: ✭ 25 (-43.18%)
Mutual labels:  natural-language-understanding
sms-analysis-with-wks
Analyzing SMS offers for domain specific entities using Watson Knowledge Studio and Watson's Natural Language Understanding
Stars: ✭ 17 (-61.36%)
Mutual labels:  natural-language-understanding
LearningMetersPoems
Official repo of the article: Yousef, W. A., Ibrahime, O. M., Madbouly, T. M., & Mahmoud, M. A. (2019), "Learning meters of arabic and english poems with recurrent neural networks: a step forward for language understanding and synthesis", arXiv preprint arXiv:1905.05700
Stars: ✭ 18 (-59.09%)
Mutual labels:  natural-language-understanding
VCML
PyTorch implementation of paper "Visual Concept-Metaconcept Learner", NeruIPS 2019
Stars: ✭ 45 (+2.27%)
Mutual labels:  natural-language-understanding
TextFeatureSelection
Python library for feature selection for text features. It has filter method, genetic algorithm and TextFeatureSelectionEnsemble for improving text classification models. Helps improve your machine learning models
Stars: ✭ 42 (-4.55%)
Mutual labels:  natural-language-understanding
spokestack-ios
Spokestack: give your iOS app a voice interface!
Stars: ✭ 27 (-38.64%)
Mutual labels:  natural-language-understanding
dstqa
Code for Li Zhou, Kevin Small. Multi-domain Dialogue State Tracking as Dynamic Knowledge Graph Enhanced Question Answering. In NeurIPS 2019 Workshop on Conversational AI
Stars: ✭ 26 (-40.91%)
Mutual labels:  natural-language-understanding
minie
An open information extraction system that provides compact extractions
Stars: ✭ 83 (+88.64%)
Mutual labels:  natural-language-understanding
nlcli
Natural language interface for the command line.
Stars: ✭ 21 (-52.27%)
Mutual labels:  natural-language-understanding
Natural-language-understanding-papers
NLU: domain-intent-slot; text2SQL
Stars: ✭ 77 (+75%)
Mutual labels:  natural-language-understanding
SelSum
Abstractive opinion summarization system (SelSum) and the largest dataset of Amazon product summaries (AmaSum). EMNLP 2021 conference paper.
Stars: ✭ 36 (-18.18%)
Mutual labels:  natural-language-understanding
label-studio-transformers
Label data using HuggingFace's transformers and automatically get a prediction service
Stars: ✭ 117 (+165.91%)
Mutual labels:  natural-language-understanding
slotminer
Tool for slot extraction from text
Stars: ✭ 15 (-65.91%)
Mutual labels:  natural-language-understanding
Question-Answering-based-on-SQuAD
Question Answering System using BiDAF Model on SQuAD v2.0
Stars: ✭ 20 (-54.55%)
Mutual labels:  natural-language-understanding
NLP-Natural-Language-Processing
Projects and useful articles / links
Stars: ✭ 149 (+238.64%)
Mutual labels:  natural-language-understanding
sepia-assist-server
Core server of the SEPIA Framework responsible for NLU, conversation, smart-service integration, user-accounts and more.
Stars: ✭ 81 (+84.09%)
Mutual labels:  natural-language-understanding
OpenPrompt
An Open-Source Framework for Prompt-Learning.
Stars: ✭ 1,769 (+3920.45%)
Mutual labels:  natural-language-understanding
DeepChem-Workshop
DeepChem 2017: Deep Learning & NLP for Computational Chemistry, Biology & Nano-materials
Stars: ✭ 22 (-50%)
Mutual labels:  natural-language-understanding
text-bot-openwhisk
DEPRECATED: this repo is no longer actively maintained
Stars: ✭ 12 (-72.73%)
Mutual labels:  natural-language-understanding
smart-email-support
Smart Email Support for Telecom Organisations - Provide automated customer support for emails
Stars: ✭ 19 (-56.82%)
Mutual labels:  natural-language-understanding

Conversational Sentence Encoder

GitHub license GitHub issues GitHub forks GitHub stars

This project features the ConveRT dual-encoder model, using subword representations and lighter-weight more efficient transformer-style blocks to encode text, as described in the ConveRT paper. It provides powerful representations for conversational data, and can also be used as a response ranker. Also it features the multi-context ConveRT model, that uses extra contexts from the conversational history to refine the context representations. The extra contexts are the previous messages in the dialogue (typically at most 10) prior to the immediate context.

Installation

Just pip install the package (works for python 3.6.* and 3.7.*) and you are ready to go!

pip install conversational-sentence-encoder

Usage examples

The entry point of the package is SentenceEncoder class:

from conversational_sentence_encoder.vectorizers import SentenceEncoder

To run the examples you will also need to

pip install scikit-learn

Text Classification / Intent Recognition / Sentiment Classification Open In Colab

The ConveRT model encodes sentences to a meaningful semantic space. Sentences can be compared for semantic similarity in this space, and NLP classifiers can be trained on top of these encodings

from sklearn import preprocessing
from sklearn.neighbors import KNeighborsClassifier

# texts
X = ["hello ? can i speak to a actual person ?",
"i ll wait for a human to talk to me",
"i d prefer to be speaking with a human .",
"ok i m not talking to a real person so",
"ok . this is an automated message . i need to speak with a real human",
"hello . i m so sorry but i d like to return . can you send me instructions . thank you",
"im sorry i m not sure you understand what i need but i need to return a package i got from you guys",
"how can i return my order ? no one has gotten back to me on here or emails i sent !",
"i can t wait that long . even if the order arrives i will send it back !",
"i have a question what is your return policy ? i ordered the wrong size"]

# labels
y = ["SPEAK_HUMAN"]*5+["RETURN"]*5

# initialize the ConveRT dual-encoder model
sentence_encoder = SentenceEncoder(multiple_contexts=False)

# output 1024 dimensional vectors, giving a representation for each sentence. 
X_encoded = sentence_encoder.encode_sentences(X)

# encode labels
le = preprocessing.LabelEncoder()
y_encoded = le.fit_transform(y)

# fit the KNN classifier on the toy dataset
clf = KNeighborsClassifier(n_neighbors=3).fit(X_encoded, y_encoded)


test = sentence_encoder.encode_sentences(["are you all bots???", 
                                          "i will send this trash back!"])

prediction = clf.predict(test)

# this will give the intents ['SPEAK_HUMAN' 'RETURN']
print(le.inverse_transform(prediction))

Response Selection (Neural Ranking) Open In Colab

ConveRT is trained on the response ranking task, so it can be used to find good responses to a given conversational context.

This section demonstrates how to rank responses, by computing cosine similarities of context and response representations in the shared response ranking space. Response representations for a fixed candidate list are first pre-computed. When a new context is provided, it is encoded and then compared to the pre-computed response representations.

import numpy as np

# initialize the ConveRT dual-encoder model
sentence_encoder = SentenceEncoder(multiple_contexts=False)

questions = np.array(["where is my order?", 
                      "what is the population of London?",
                      "will you pay me for collaboration?"])

# outputs 512 dimensional vectors, giving the context representation of each input. 
#These are trained to have a high cosine-similarity with the response representations of good responses
questions_encoded = sentence_encoder.encode_contexts(questions)


responses = np.array(["we expect you to work for free",
                      "there are a lot of people",
                      "its on your way"])

# outputs 512 dimensional vectors, giving the response representation of each input. 
#These are trained to have a high cosine-similarity with the context representations of good corresponding contexts
responses_encoded = sentence_encoder.encode_responses(responses)

# computing pairwise similarities as a dot product
similarity_matrix = questions_encoded.dot(responses_encoded.T)

# indices of best answers to given questions
best_idx = np.argmax(similarity_matrix, axis=1)

# will output answers in the right order
# ['its on your way', 'there are a lot of people', 'we expect you to work for free']
print(np.array(responses)[best_idx])

Multi-context response ranking/similarity/classification Open In Colab

This model takes extra dialogue history into account allowing to create smart conversational agents

import numpy as np
from conversational_sentence_encoder.vectorizers import SentenceEncoder

# initialize the multi-context ConveRT model, that uses extra contexts from the conversational history to refine the context representations
multicontext_encoder = SentenceEncoder(multiple_contexts=True)

dialogue = np.array(["hello", "hey", "how are you?"])

responses = np.array(["where do you live?", "i am fine. you?", "i am glad to see you!"])

# outputs 512 dimensional vectors, giving the whole dialogue representation
dialogue_encoded = multicontext_encoder.encode_multicontext(dialogue)

# encode response candidates using the same model
responses_encoded = multicontext_encoder.encode_responses(responses)

# get the degree of response fit to the existing dialogue
similarities = dialogue_encoded.dot(responses_encoded.T)

# find the best response
best_idx = np.argmax(similarities)

# will output "i am fine. you?"
print(responses[best_idx])

Notes

This project is a continuation of the abandoned https://github.com/PolyAI-LDN/polyai-models, it is distributed under the same license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].