Skip to content

Instantly share code, notes, and snippets.

@YasuThompson
Created January 27, 2021 13:28
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 YasuThompson/4d3dff35ddba2053ba5579172be94123 to your computer and use it in GitHub Desktop.
Save YasuThompson/4d3dff35ddba2053ba5579172be94123 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[('<start>', 1),\n",
" ('<end>', 2),\n",
" ('.', 3),\n",
" ('tom', 4),\n",
" ('?', 5),\n",
" ('¿', 6),\n",
" ('es', 7),\n",
" ('no', 8)]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"'''\n",
" Let's see the first and last 8 tokens in the dictionary. \n",
"'''\n",
"list(inp_lang.word_index.items())[:8]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[('caminamos', 9406),\n",
" ('divertir', 9407),\n",
" ('divertiremos', 9408),\n",
" ('divertirnos', 9409),\n",
" ('decepcionaremos', 9410),\n",
" ('viviremos', 9411),\n",
" ('reyes', 9412),\n",
" ('perderemos', 9413)]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list(inp_lang.word_index.items())[-8:]"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1, 74, 514, 19, 237, 3, 2]\n"
]
}
],
"source": [
"'''\n",
" Let's conversely encode a Spanish sentence into integer codes. \n",
" For the neural net which we are going to make, \"Todo sobre mi madre.\" is comprehensed as \n",
" [1, 74, 514, 19, 237, 3, 2]\n",
"''' \n",
"sentence = preprocess_sentence('Todo sobre mi madre.')\n",
"inputs = [inp_lang.word_index[i] for i in sentence.split(' ')]\n",
"print(inputs)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.9"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment