This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Extras for Linux Mint 19 | |
# VirtualBox | |
wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add - | |
echo "deb [arch=amd64] http://download.virtualbox.org/virtualbox/debian bionic contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list | |
# git | |
sudo add-apt-repository ppa:git-core/ppa |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- king - man + woman | |
with q ( | |
id, | |
w | |
) as ( | |
select w.id, +1.0 from fasttext.word as w where (w.word = 'king') | |
union | |
select w.id, -1.0 from fasttext.word as w where (w.word = 'man') | |
union |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model = "C:\\Data\\fasttext\\wiki\\enwik9.bin"; | |
console.log("Loading file \"%s\"...", model); | |
fasttext.loadModel(model); | |
console.log("done."); | |
console.log("Computing vectors..."); | |
vectors = fasttext.precomputeVectors(); | |
try { | |
console.log("done."); | |
while (true) { | |
positive = prompt('positive words:'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type | |
TFastTextObject = class(TNativeObject) | |
private | |
FCallback: JsValueRef; | |
FHandle: TFastText; | |
procedure NN2Callback(const Word: string; Score: Single); | |
protected | |
class procedure RegisterMethods(AInstance: JsHandle); override; | |
public |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function nn_callback(word: PAnsiChar; score: Single; data: Pointer): LongBool; cdecl; | |
begin | |
Result := False; | |
Writeln(Format('''%s'': %f', [word, score])); | |
end; | |
procedure TFastTextConsole.NN2(const ModelFileName: string); | |
var | |
ft: TFastText; | |
mx: TMatrix; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static bool NearestNeighborsCallback(string word, Single score) | |
{ | |
Console.WriteLine($"\"{word}\": {score}"); | |
return false; | |
} | |
static void NearestNeighbors(string modelFileName) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public delegate bool WordCallback(string word, Single score); | |
class FastText : IDisposable | |
{ | |
private IntPtr ft = IntPtr.Zero; | |
private WordCallback c = null; | |
private void FastTextCheck(bool result) | |
{ | |
if (!result) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class FastTextWrapper | |
{ | |
[return: MarshalAs(UnmanagedType.Bool)] | |
[UnmanagedFunctionPointer(callingConvention: CallingConvention.Cdecl, CharSet = CharSet.Ansi)] | |
public delegate bool FastTextNNCallback(StringBuilder word, Single score, IntPtr data); | |
[DllImport(dllName: "fasttext.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true)] | |
[return: MarshalAs(UnmanagedType.Bool)] | |
public static extern bool fasttext_new(out IntPtr ft); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const | |
FastTextLib = 'fasttext.dll'; | |
type | |
TFastTextNNCallback = function(word: PAnsiChar; score: Single; data: Pointer): LongBool; cdecl; | |
function fasttext_new(out ft: TFastText): LongBool; cdecl; external FastTextLib; | |
function fasttext_release(ft: TFastText): LongBool; cdecl; external FastTextLib; | |
function fasttext_nn2(ft: TFastText; mx: TMatrix; positive, negative: PPAnsiChar; count: Integer; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FASTTEXT_API BOOL FASTTEXT_CC fasttext_new(FastText** ft) | |
{ | |
return ExceptionBoundary([&]() -> BOOL | |
{ | |
*ft = new FastText(); | |
return true; | |
}); | |
} | |
FASTTEXT_API BOOL FASTTEXT_CC fasttext_release(FastText* ft) |