Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,6 @@ tags

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history

### VisualStudio ###
Expand Down
171 changes: 0 additions & 171 deletions .vscode/settings.json

This file was deleted.

76 changes: 0 additions & 76 deletions .vscode/tasks.json

This file was deleted.

25 changes: 24 additions & 1 deletion fasttext.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,30 @@ func (handle Model) Wordvec(word string) []float32 {
},
)

defer C.FastText_FreeFloatVector(r)
defer C.FastText_FreeFloatVector(r)

vectors := make([]float32, r.size)
ptr := (*float32)(unsafe.Pointer(r.data))
copy(vectors, unsafe.Slice(ptr, r.size))
return vectors
}

func (handle Model) Sentencevec(sentence string) []float32 {
var pinner runtime.Pinner
defer pinner.Unpin()

strData := cStr(sentence)
pinner.Pin(strData)

r := C.FastText_Sentencevec(
handle.p,
C.FastText_String_t{
data: strData,
size: C.size_t(len(sentence)),
},
)

defer C.FastText_FreeFloatVector(r)

vectors := make([]float32, r.size)
ptr := (*float32)(unsafe.Pointer(r.data))
Expand Down
19 changes: 10 additions & 9 deletions fasttext/include/fasttext.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
namespace fasttext
{

class FastText
{
class FastText
{
public:
using TrainCallback = std::function<void(float, float, double, double, int64_t)>;

Expand Down Expand Up @@ -91,8 +91,8 @@ class FastText

inline void getInputVector(Vector &vec, int32_t ind)
{
vec.zero();
addInputVector(vec, ind);
vec.zero();
addInputVector(vec, ind);
}

const Args getArgs() const;
Expand All @@ -115,6 +115,7 @@ class FastText

void loadModel(const std::string &filename);

Vector getSentenceVector(std::istream &in) const;
void getSentenceVector(std::istream &in, Vector &vec);

void quantize(const Args &qargs, const TrainCallback &callback = {});
Expand Down Expand Up @@ -147,10 +148,10 @@ class FastText

class AbortError : public std::runtime_error
{
public:
AbortError() : std::runtime_error("Aborted.")
{
}
public:
AbortError() : std::runtime_error("Aborted.")
{
}
};
};
};
} // namespace fasttext
Loading