Skip to content

Instantly share code, notes, and snippets.

@peckjon
Created August 1, 2018 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peckjon/ebee5d8befefa8a352804987212a5ca1 to your computer and use it in GitHub Desktop.
Save peckjon/ebee5d8befefa8a352804987212a5ca1 to your computer and use it in GitHub Desktop.
Train a Machine to Turn Documents into Keywords, via Document Classification
import Algorithmia
remote_url = 'data://.my/collection/training_data.json'
local_dataset = '/path/to/my/training_dataset.json'
client = Algorithmia.client('YOUR_API_KEY_HERE')
client.file(remote_url).putFile(local_dataset)
import Algorithmia
client = Algorithmia.client('YOUR_API_KEY_HERE')
input = {
"data": [{
"text": "Attention-based neural encoder-decoder frameworks have been widely adopted for image captioning. Most methods force visual attention to be active for every generated word. However, the decoder likely requires little to no visual information from the image to predict non-visual words such as the and of. Other words that may seem visual can often be predicted reliably just from the language model e.g., sign after behind a red stop or phone following talking on a cell."
}],
"namespace": "data://.my/my_new_classifier",
"mode": "predict"
}
result = client.algo('algo://nlp/DocumentClassifier/0.3.0').pipe(input)
print(result)
{
"text": "Attention-based neural encoder-decoder frameworks have been widely adopted for image captioning. Most methods force visual attention to be active for every generated word. However, the decoder likely requires little to no visual information from the image to predict non-visual words such as the and of. Other words that may seem visual can often be predicted reliably just from the language model e.g., sign after behind a red stop or phone following talking on a cell.",
"topN": [{
"prediction": "language",
"confidence": 0.2066967636346817
}, {
"prediction": "deep learning",
"confidence": 0.2053375542163849
}, {
"prediction": "world war 2",
"confidence": 0.20009714365005493
}, {
"prediction": "solar",
"confidence": 0.19612550735473633
}, {
"prediction": "biological",
"confidence": 0.19174303114414215
}]
}
import Algorithmia
client = Algorithmia.client('YOUR_API_KEY_HERE')
input = {
"data": "data://.my/collection/training_data.json",
"namespace": "data://.my/my_new_classifier",
"mode": "train"
}
result = client.algo('algo://nlp/DocumentClassifier/0.3.0').set_options(timeout=3000).pipe(input)
import Algorithmia client = Algorithmia.client('YOUR_API_KEY_HERE')
input = {
"data": "data://.my/collection/more_training_data.json",
"namespace": "data://.my/my_new_classifier",
"mode": "train"
}
result = client.algo('algo://nlp/DocumentClassifier/0.3.0').set_options(timeout=3000).pipe(input)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment