Giter Site home page Giter Site logo

dssmtest's Introduction

Deep Structured Semantic Modeling with LSTM Networks

This service is an implementation of Deep Structured Semantic Model or Deep Semantic Similarity Model (DSSM) with LSTM Networks. Given a query and a pair of answers from the sample data the network trained, it returns the better answer based on the cosine similarity. It is forked from CNTK 303: Deep Structured Semantic Modeling with LSTM.

Deep Structured Semantic Model (DSSM)

DSSM is a Deep Neural Network (DNN) modeling technique for representing text strings in a continuous semantic space and modeling semantic similarity (a metric defined over a set of documents or terms where the distance between them based on the likeness of their semantic content or meaning) between text strings. Its application include information retrieval, web search ranking, ad selection/relevance, question answering and machine translation.

Given a pair of documents, this model would map the inputs to a pair of feature vectors in a continuous, low dimensional space where one could compare the semantic similarity between the text strings using the cosine similarity between their vectors in that space.

Semantic Modeling

In the above figure, the given query (Q) and set of documents (D_1, D_2, ..., D_n) generate semantic features, which can then be used to generate pairwise distance metric.

Models

The data set is preprocessed into two parts. There are Vocabulary files (one each for question and asnwers in .wl format) and CTF format question and answer files (CTF deserializer is used to read input data).

With LSTM-RNN (Long-Short Term Memory and Recurrent Neural Network) (1), it sequentially takes each word in a sentence, extracts its information, and embeds it into a semantic vector.

Semantic Feature

The above figure illustrated how query_vector space projected with the semantic representation of sentences and there would be a similar projection for the answer_vector.

Parameters

One could refine parameters associated with the network architecture at Variables.txt. Default values set to suite the sample model found in data directory.

Setup

A sampling of QA dataset is populated in data with vocablary (WL format) and QA (CTF format) files, which would populate data/DSSM

Set up a virtualenv

  	mkvirtualenv --python=/usr/bin/python3.6 semantic-modeling

Install required packages

  	pip install -r requirements.txt

Run the following commad to generate gRPC class for Python

	python -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. service_spec/DSSMService.proto

Using docker

		docker build . -t singnet:semmodeling

How to use the docker image

To run with grpc endpoint

	docker run -it --rm -p 8001:8001 singnet:semmodeling python3.6 script.py

Running the service

The service accepts a query and two answers phrases. The query and answers entry should be from the available sample data for the service to create vector representation and compute the similarity.

	python3.6 service.py --qry=qry_string --ans1=first_answer --ans2=second_answer

Authors

Licenses

Microsoft Cognitive Toolkit (CNTK)

Copyright (c) Microsoft Corporation. All rights reserved.

MIT License

References

(1) https://towardsdatascience.com/recurrent-neural-networks-and-lstm-4b601dd822a5

dssmtest's People

Contributors

eskendertamrat avatar

Watchers

James Cloos avatar  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.