Created
May 23, 2022 08:55
-
-
Save titomus/266d819990b21579bd3078ab75fe1f64 to your computer and use it in GitHub Desktop.
Tokenize js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tokenize(txt) { | |
// on sépare en phrases pour avoir quelques points de départ dans la génération | |
let tokens = []; | |
const sentences = txt.split(/\n/gim).filter((x) => x); | |
// on tokenize chaque phrase en splitant les mots | |
for (let i = 0; i < sentences.length; i++) { | |
// on insert un START | |
tokens.push("START"); | |
let tks = sentences[i].match(/\S+/gim).filter((x) => x); | |
tks.map((token) => tokens.push(token)); | |
} | |
return tokens; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment