# DSSM-LSTM **Repository Path**: giteemirror/DSSM-LSTM ## Basic Information - **Project Name**: DSSM-LSTM - **Description**: origin url: https://github.com/EskenderTamrat/DSSM-LSTM - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2021-09-23 - **Last Updated**: 2024-05-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ![singnetlogo](docs/assets/singnet-logo.jpg?raw=true 'SingularityNET') [![CircleCI](https://circleci.com/gh/EskenderTamrat/DSSM-LSTM.svg?style=svg)](https://circleci.com/gh/EskenderTamrat/DSSM-LSTM) # 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](https://github.com/Microsoft/CNTK/blob/master/Tutorials/CNTK_303_Deep_Structured_Semantic_Modeling_with_LSTM_Networks.ipynb). ## 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 ```bash mkvirtualenv --python=/usr/bin/python3.6 semantic-modeling ``` Install required packages ```bash pip install -r requirements.txt ``` Run the following commad to generate gRPC class for Python ```bash python -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. service_spec/DSSMService.proto ``` # Using docker ```bash docker build . -t singnet:semmodeling ``` # How to use the docker image To run with grpc endpoint ```bash 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 have terms from the available sample data for the service to create vector representation and compute the similarity. ```bash python3.6 service.py --qry qry_string --ans1 first_answer --ans2 second_answer ``` Example usage: ```bash python3.6 service.py --qry "what contribution did you made to science" --ans1 "book author book_editions_published" --ans2 "activism address adjoining_relationship" ``` # Authors - Eskender Tamrat - Maintainer - [SingularityNet.io](https://singularitynet.io) # 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