Skip to content

Instantly share code, notes, and snippets.

View fsndzomga's full-sized avatar

Franck Stéphane Ndzomga fsndzomga

View GitHub Profile
@fsndzomga
fsndzomga / space-tokenize.py
Created September 7, 2023 11:48
Tokenize using spaCy
import spacy
nlp = spacy.load("en_core_web_sm")
doc = nlp("Natural Language Processing is fascinating.")
tokens = [token.text for token in doc]
print(tokens)
# Output: ['Natural', 'Language', 'Processing', 'is', 'fascinating', '.']
@fsndzomga
fsndzomga / stem.py
Last active September 7, 2023 18:10
stemming and lemmatisation
# using nltk
from nltk.stem import PorterStemmer
stemmer = PorterStemmer()
print(stemmer.stem("running")) # Output: 'run'
print(stemmer.stem("flies")) # Output: 'fli'
import spacy
@fsndzomga
fsndzomga / rlSimple.py
Created September 7, 2023 16:17
rl simple
import numpy as np
import pandas as pd
import time
np.random.seed(2) # reproducible
ROWS, COLS = 2, 2 # dimensions of the 2D world
ACTIONS = ['left', 'right', 'up', 'down'] # available actions
EPSILON = 0.9 # greedy policy
ALPHA = 0.1 # learning rate
@fsndzomga
fsndzomga / stopwords.py
Created September 7, 2023 22:53
stop words
from spacy.lang.en.stop_words import STOP_WORDS
sentence = "This is a sample sentence."
doc = nlp(sentence)
filtered_tokens = [token.text for token in doc if token.text.lower() not in STOP_WORDS]
print(filtered_tokens)
# Output: ['sample', 'sentence', '.']
@fsndzomga
fsndzomga / ngrams.py
Created September 7, 2023 22:59
n grams
from nltk.util import ngrams
from nltk.tokenize import word_tokenize
sentence = "I love coding and learning"
tokenized_sentence = word_tokenize(sentence)
bigrams = list(ngrams(tokenized_sentence, 2))
print(bigrams)
# Output: [('I', 'love'), ('love', 'coding'), ('coding', 'and'), ('and', 'learning')]
@fsndzomga
fsndzomga / basic-q-learning.py
Created September 8, 2023 00:03
Q learning basics
import numpy as np
import pandas as pd
import time
class QLearningAgent:
def __init__(self, n_states, actions, epsilon, alpha, gamma, max_episodes, fresh_time):
self.n_states = n_states
self.actions = actions
self.epsilon = epsilon
@fsndzomga
fsndzomga / data_anonymizer.py
Created September 8, 2023 15:43
LangChain Data Anonymizer
from langchain_experimental.data_anonymizer import PresidioAnonymizer
from faker import Faker
fake = Faker()
DATA = []
DATA_ANON = []
for _ in range(2):
@fsndzomga
fsndzomga / anonymize.py
Created September 8, 2023 15:58
Anonymize without LangChain
import re
import spacy
import hashlib
from faker import Faker
fake = Faker()
nlp = spacy.load("en_core_web_sm")
DATA = []
DATA_ANON = []
@fsndzomga
fsndzomga / anon.py
Created September 8, 2023 23:06
anonLLM example
from anonLLM.llm import OpenaiLanguageModel
from dotenv import load_dotenv
load_dotenv()
text = "Write a CV for me: My name is Alice Johnson, "\
"email: [email protected], phone: +1 234-567-8910."\
"I am a machine learning engineer."
llm = OpenaiLanguageModel()
@fsndzomga
fsndzomga / maze.py
Created September 9, 2023 23:17
Reinforcement learning Maze
import tkinter as tk
import pandas as pd
import numpy as np
import time
class QLearningTable:
# Initialize parameters and create a Q-table
def __init__(self, actions, learning_rate=0.01, reward_decay=0.9, e_greedy=0.9):
self.actions = actions
self.lr = learning_rate