This file contains hidden or 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
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', '.'] |
This file contains hidden or 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
# using nltk | |
from nltk.stem import PorterStemmer | |
stemmer = PorterStemmer() | |
print(stemmer.stem("running")) # Output: 'run' | |
print(stemmer.stem("flies")) # Output: 'fli' | |
import spacy |
This file contains hidden or 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
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 |
This file contains hidden or 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
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', '.'] |
This file contains hidden or 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
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')] |
This file contains hidden or 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
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 |
This file contains hidden or 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
from langchain_experimental.data_anonymizer import PresidioAnonymizer | |
from faker import Faker | |
fake = Faker() | |
DATA = [] | |
DATA_ANON = [] | |
for _ in range(2): |
This file contains hidden or 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
import re | |
import spacy | |
import hashlib | |
from faker import Faker | |
fake = Faker() | |
nlp = spacy.load("en_core_web_sm") | |
DATA = [] | |
DATA_ANON = [] |
This file contains hidden or 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
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() |
This file contains hidden or 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
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 |