The WordEmbeddings model is a VB.NET implementation of the Word Embeddings technique, which represents words as dense vectors in a continuous vector space. This model allows you to train word embeddings on a given corpus and perform various operations such as calculating similarity between words, discovering collocations, and generating training data.
The Positional Encoder Decoder is a Visual Basic .NET class that provides functionality for encoding and decoding tokens and sentences using positional embeddings. It allows you to convert between string tokens and their corresponding embeddings, and vice versa.
Install the necessary dependencies (e.g., .NET framework) for running VB.NET applications.
Clone or download the repository to your local machine.
Import the WordEmbeddings class into your VB.NET project.
Initialize an instance of the WordEmbeddings model with the desired parameters:
Dim model As New WordEmbeddings(embeddingSize:=100, learningRate:=0.01, windowSize:=5)
Dim corpus As String() = {
"united states is a country.", "England is a country",
"the united kingdom is in europe.",
"united airlines is an airline company.",
"doberman is a breed of dog.",
"dogs have many breeds.",
"dogs love eating pizza."
}
model.Train(corpus)
Dim pmiMatrix As Dictionary(Of String, Dictionary(Of String, Double)) = model.CalculatePMI()
Dim words As String() = {"united", "states", "kingdom", "airlines"}
Dim collocations As List(Of Tuple(Of String, String)) = model.DiscoverCollocations(words, threshold:=1)
Dim similarWords As List(Of String) = model.GetMostSimilarWords("dog", topK:=3)
' Save the model
model.SaveModel("path/to/save/model.json")
' Load the model
Dim loadedModel As WordEmbeddings = WordEmbeddings.LoadModel("path/to/saved/model.json")
PositionalEncoderDecoder
classby providing the necessary parameters: Dmodel
(embedding model size), MaxSeqLength
(maximum sentence length), and vocabulary
(a list of known vocabulary).
Dim encoderDecoder As New PositionalEncoderDecoder(Dmodel, MaxSeqLength, vocabulary)
Dim token As String = "example"
Dim embedding As List(Of Double) = encoderDecoder.EncodeTokenStr(token)
Dim tokenEmbedding As List(Of Double) = GetTokenEmbedding() ' Get the token embedding from somewhere
Dim embedding As List(Of Double) = encoderDecoder.EncodeTokenEmbedding(tokenEmbedding)
Dim sentence As New List(Of String) From {"This", "is", "an", "example"}
Dim embeddings As List(Of List(Of Double)) = encoderDecoder.EncodeSentenceStr(sentence)
Dim sentenceEmbeddings As List(Of List(Of Double)) = GetSentenceEmbeddings() ' Get the token embeddings from somewhere
Dim embeddings As List(Of List(Of Double)) = encoderDecoder.EncodeSentenceEmbedding(sentenceEmbeddings)
Dim embeddings As New List(Of List(Of Double)) From {embedding1, embedding2, embedding3}
Dim tokens As List(Of String) = encoderDecoder.DecodeSentenceStr(embeddings)
Dim embeddings As New List(Of List(Of Double)) From {embedding1, embedding2, embedding3}
Dim tokenEmbeddings As List(Of List(Of Double)) = encoderDecoder.DecodeSentenceEmbedding(embeddings)
Dim embedding As List(Of Double) = GetPositionalEmbedding() ' Get the positional embedding from somewhere
Dim token As String = encoderDecoder.DecodeTokenStr(embedding)
Dim embedding As List(Of Double) = GetPositionalEmbedding() ' Get the positional embedding from somewhere
Dim tokenEmbedding As List(Of Double) = encoderDecoder.DecodeTokenEmbedding(embedding)
The WordEmbeddings model requires the following dependencies:
License This project is licensed under the MIT License.
Contributions to the WordEmbeddings model are welcome! If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.