Tokenizer - Module python d'analyse syntaxique et de grammaire, tokenization

Overview

Tokenizer

Le Tokenizer est un analyseur lexicale, il permet, comme Flex and Yacc par exemple, de tokenizer du code, c'est à dire transformer du code en liste tokens. En l'occurence, contrairement à Flex and Yacc, la liste de token sera hiérarchisée et les tokens sont typés.

Qu'est-ce que c'est quoi dis donc un token ?

Un token, litteralement, c'est un jeton... Bof bof comme définition... Repprenons. Un token c'est une chaîne de caractères qui, ensemble, ont une signification. La chaîne de caractères qui forme un jeton est appelée Lexeme.

Et à quoi ça sert ?

La tokenization, c'est la prmière étape de la compilation ou de l'interprétation de la plupart des langages informatiques. Prenons Python par exemple, l'ordinateur ne sait absolument pas quoi faire avec le ficher qu'on lui donne, il le découpe donc pour avoir chacun des mots du code et pouvoir comprendre ce qu'on lui demande.


Exemple :

Du code python comme celui ci :

def hello(name) :
    print("Hello", name, "!")

sera convertit en YAML (ou n'importe quel autre langage de stockage de données comme JSON par exemple)

---
- {value: 'def', type: function.declaration}
- {value: 'hello', type: name.funciton.declaration}
- {value: '(', type: punctuation.begin}
- {value: 'name', type: parameter}
- {value: ')', type: punctuation.end}
- {value: ':', type: start.node}
- - {value: 'print', type: function}
  - {value: '(', type: punctuation.begin}
  - {value: '"Hello"', type: string}
  - {value: ',', type: separator}
  - {value: 'name', type: variable}
  - {value: ',', type: separator}
  - {value: '"!"', type: string}
  - {value: ')', type: punctuation.end}

Ici les tokens sont hiérarchisés et typés, c'est à dire que pour chaque nœud, une nouvelle liste est créée et pour chaque token, un attribut de type lui est appliqué.

Le typage des tokens peut être utile car le tokenizateur peut, avec une grammaire, faire un fichier de coloration syntaxique si l'on indique dans le type la couleur du token.


Spécifications

technologie outil
Langage Python
Version du langage 3.10
Gestionnaire des packets PIP
Gestionnaire d'environnement VirtualEnvironment
Environnement Windows 7/10
Librairie PyYaml, re

Installation

pip install -e git+https://github.com/Manolo-dev/tokenizer.git#egg=tokenizer


To do list

  • Grammaire
  • Classe Token
  • Classe Node
  • Main
  • Gestion des erreurs
  • Lecteur Yaml

Grammaire

Oui, il faut une grammaire à l'outil de grammaire ! Grammaception !

Corps

Le corps se compose d'au moins deux parties, variables, qui contient des expressions regexp, et les modules, dont main, seul module obligatoire.

  • variables

  • main

Module

main est le seul module qui est appelé sans qu'on l'incluse manuellement.

Les modules traitent le code et s'occupe de la grosse part du travail, ils peuvent utiliser les variables définies dans le module, dans un module encore ouvert (variables locale) ou dans variables.

Méthodes

  • include, inclut un module.

  • match, corresptond à un SI token correspond FAIRE, assigne à l'objet courant le token trouvé et éxécute le module donné (nommé ou non).

  • save, assigne un type à l'objet courant et enregistre le token dans la liste des tokens.

  • if, vérifie la condition donnée (liste de trois arguments, le premier l'opérateur, le second et le troisième les valeurs à tester). Exemple: if: ['==', ;a, ;b]

  • begin, crée un nœud et le débute.

  • end, ferme le nœud.

  • ignore, ne fait pas avancer le texte.

  • var, modifie les variables de la même manière que le module variables, la variable _ représente le token trouvé.

  • error, génère une erreur (équivalent au raise python)

  • print, affiche le texte donné dans la console.

Variables

Il y deux moyens d'utiliser les variables. Dans le cas d'une variable d'exemple appelée var, on peut faire :

  • ;var, seul dans l'élément.

  • {{var}}, peut-être placé n'importe où dans l'élément.

  • str:n, permet de supprimer n caractères à la chaîne str.

Exemple

variables:
  open: '\('
  close: '\)'
main:
  - match: ;open
    save: 'open'
    begin: # Ceci est un module non nommé
    - match: ;close
      save: 'close'
      end: 1
    - include: 'main'
  - match: '[^()]+' # pour éviter de prendre des parenthèses involontairement
    save: 'other'
  - match: ;close
    error: il y a une parenthèse de fermeture en trop

Cette grammaire fait de la parenthétisation simple, en simple, ça transforme ceci :

1 / (3 * (1 + 2))

en :

---
- {value: '1 / ', type: 'other'}
- {value: '(', type: 'open'}
- - {value: '3 * ', type: 'other'}
  - {value: '(', type: 'open'}
  - - {value: '1 + 2', type: 'other'}
  - {value: ')', type: 'close'}
- {value: ')', type: 'close'}
Owner
Manolo
Hi ! My name is Manolo, I am 18 years old. I have been programming since I was 11 or 12 (I can't quite remember) with BASIC CASIO. And i love code !
Manolo
Implementation / replication of DALL-E, OpenAI's Text to Image Transformer, in Pytorch

Implementation / replication of DALL-E, OpenAI's Text to Image Transformer, in Pytorch

Phil Wang 5k Jan 02, 2023
Deal or No Deal? End-to-End Learning for Negotiation Dialogues

Introduction This is a PyTorch implementation of the following research papers: (1) Hierarchical Text Generation and Planning for Strategic Dialogue (

Facebook Research 1.4k Dec 29, 2022
jel - Japanese Entity Linker - is Bi-encoder based entity linker for japanese.

jel: Japanese Entity Linker jel - Japanese Entity Linker - is Bi-encoder based entity linker for japanese. Usage Currently, link and question methods

izuna385 10 Jan 06, 2023
BERN2: an advanced neural biomedical namedentity recognition and normalization tool

BERN2 We present BERN2 (Advanced Biomedical Entity Recognition and Normalization), a tool that improves the previous neural network-based NER tool by

DMIS Laboratory - Korea University 99 Jan 06, 2023
Twitter-Sentiment-Analysis - Analysis of twitter posts' positive and negative score.

Twitter-Sentiment-Analysis The hands-on project is in Python 3 Programming class offered by University of Michigan via Coursera. The task is to build

Eszter Pai 1 Jan 03, 2022
A Word Level Transformer layer based on PyTorch and 🤗 Transformers.

Transformer Embedder A Word Level Transformer layer based on PyTorch and 🤗 Transformers. How to use Install the library from PyPI: pip install transf

Riccardo Orlando 27 Nov 20, 2022
🛸 Use pretrained transformers like BERT, XLNet and GPT-2 in spaCy

spacy-transformers: Use pretrained transformers like BERT, XLNet and GPT-2 in spaCy This package provides spaCy components and architectures to use tr

Explosion 1.2k Jan 08, 2023
Disfl-QA: A Benchmark Dataset for Understanding Disfluencies in Question Answering

Disfl-QA is a targeted dataset for contextual disfluencies in an information seeking setting, namely question answering over Wikipedia passages. Disfl-QA builds upon the SQuAD-v2 (Rajpurkar et al., 2

Google Research Datasets 52 Jun 21, 2022
This Project is based on NLTK It generates a RANDOM WORD from a predefined list of words, From that random word it read out the word, its meaning with parts of speech , its antonyms, its synonyms

This Project is based on NLTK(Natural Language Toolkit) It generates a RANDOM WORD from a predefined list of words, From that random word it read out the word, its meaning with parts of speech , its

SaiVenkatDhulipudi 2 Nov 17, 2021
LUKE -- Language Understanding with Knowledge-based Embeddings

LUKE (Language Understanding with Knowledge-based Embeddings) is a new pre-trained contextualized representation of words and entities based on transf

Studio Ousia 587 Dec 30, 2022
A model library for exploring state-of-the-art deep learning topologies and techniques for optimizing Natural Language Processing neural networks

A Deep Learning NLP/NLU library by Intel® AI Lab Overview | Models | Installation | Examples | Documentation | Tutorials | Contributing NLP Architect

Intel Labs 2.9k Dec 31, 2022
PyTorch Language Model for 1-Billion Word (LM1B / GBW) Dataset

PyTorch Large-Scale Language Model A Large-Scale PyTorch Language Model trained on the 1-Billion Word (LM1B) / (GBW) dataset Latest Results 39.98 Perp

Ryan Spring 114 Nov 04, 2022
Spacy-ginza-ner-webapi - Named Entity Recognition API with spaCy and GiNZA

Named Entity Recognition API with spaCy and GiNZA I wrote a blog post about this

Yuki Okuda 3 Feb 27, 2022
:id: A python library for accurate and scalable fuzzy matching, record deduplication and entity-resolution.

Dedupe Python Library dedupe is a python library that uses machine learning to perform fuzzy matching, deduplication and entity resolution quickly on

Dedupe.io 3.6k Jan 02, 2023
Text Classification in Turkish Texts with Bert

You can watch the details of the project on my youtube channel Project Interface Project Second Interface Goal= Correctly guessing the classification

42 Dec 31, 2022
用Resnet101+GPT搭建一个玩王者荣耀的AI

基于pytorch框架用resnet101加GPT搭建AI玩王者荣耀 本源码模型主要用了SamLynnEvans Transformer 的源码的解码部分。以及pytorch自带的预训练模型"resnet101-5d3b4d8f.pth"

冯泉荔 2.2k Jan 03, 2023
Live Speech Portraits: Real-Time Photorealistic Talking-Head Animation (SIGGRAPH Asia 2021)

Live Speech Portraits: Real-Time Photorealistic Talking-Head Animation This repository contains the implementation of the following paper: Live Speech

OldSix 575 Dec 31, 2022
SpikeX - SpaCy Pipes for Knowledge Extraction

SpikeX is a collection of pipes ready to be plugged in a spaCy pipeline. It aims to help in building knowledge extraction tools with almost-zero effort.

Erre Quadro Srl 384 Dec 12, 2022
Script to download some free japanese lessons in portuguse from NHK

Nihongo_nhk This is a script to download some free japanese lessons in portuguese from NHK. It can be executed by installing the packages with: pip in

Matheus Alves 2 Jan 06, 2022
Creating an LSTM model to generate music

Music-Generation Creating an LSTM model to generate music music-generator Used to create basic sin wave sounds music-ai Contains the functions to conv

Jerin Joseph 2 Dec 02, 2021