Skip to content

Instantly share code, notes, and snippets.

@NesrineSF
Created March 30, 2021 21:08
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 NesrineSF/04b75b049e4075e198f224f82e31f936 to your computer and use it in GitHub Desktop.
Save NesrineSF/04b75b049e4075e198f224f82e31f936 to your computer and use it in GitHub Desktop.
tokenization with expert.ai NL API
text = "CNBC has commented on the robot's lifelike skin and her ability to emulate more than 60 facial expressions."
language= 'en'
output = client.specific_resource_analysis(
body={"document": {"text": text}},
params={'language': language, 'resource': 'disambiguation'
})
#to print to tokens within the sentence
print (f'{"TOKEN":{20}} ')
print (f'{"----":{20}}')
#we use the element output.tokens to subdivise the text into tokens
#start and end are the positions of the token in the analyzed text
for token in output.tokens:
print (f'{text[token.start:token.end]:{20}}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment