Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Implement python wrappers for predictions and tune speed #279

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Bowid
Copy link

@Bowid Bowid commented Dec 16, 2019

  1. Predict now use std::set instead priority_queue. From my point of
    view it is better to maintain set of fixed size and drop predictions
    with too low score immideately instead storing them in ordered manner.
  2. Implemented extension class of StarSpace to make things a bit more
    pythonic. It is definitely better to have return value instead of
    passing parameters to fill to functions. From my point of view, speed is
    not changed in case modern C++ compilers handle return of complex values
    properly without copying them.

1. Predict now use std::set instead priority_queue. From my point of
view it is better to maintain set of fixed size and drop predictions
with too low score immideately instead storing them in ordered manner.
2. Implemented extension class of StarSpace to make things a bit more
pythonic. It is definitely better to have return value instead of
passing parameters to fill to functions. From my point of view, speed is
not changed in case modern C++ compilers handle return of complex values
properly without copying them.
@Bowid
Copy link
Author

Bowid commented Dec 16, 2019

Also here is the sample, let it be here

import starwrap

model_path = '/path/to/trained/model'

args = starwrap.args()
model = starwrap.starSpace(args)
model.initFromSavedModel(model_path)

line = input("Enter text for classification: ")
parsed = model.parseDoc(line, ' ')

# Output is list of tuples in format (probability, token_id)
# Predict takes two arguments: parsed doc and maximum predictions count
tokens = model.predict(parsed, 10)

probabilities = [item[0] for item in tokens]
# Token_id is integer, thus it should be rendered to feature (string)
features = model.renderTokens(tokens)

for feature, probability in zip(features, probabilities):
    print('Feature {f} probability {p}'.format(f=feature, p=probability))

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants