Skip to content

Instantly share code, notes, and snippets.

@vinimonteiro
vinimonteiro / tokenization_spacy.py
Created October 17, 2021 11:15
Tokenization spacy
import spacy
#load core english library
nlp = spacy.load("en_core_web_sm")
text_english = """Imagine this: instead of sending a four-hundred-pound rover vehicle to Mars,
we merely shoot over to the planet a single sphere, one that can fit on the end of a pin.
Using energy from sources around it, the sphere divides itself into a diversified army of
similar spheres. The spheres hang on to each other and sprout features: wheels, lenses,
temperature sensors, and a full internal guidance system. You'd be gobsmacked to watch
@vinimonteiro
vinimonteiro / sent_seg.py
Created October 16, 2021 17:21
sentence segmentation
#import spacy library
import spacy
#load core english library
nlp = spacy.load("en_core_web_sm")
#take unicode string
#here u stands for unicode
doc = nlp(u"Clairson International Corp. said it expects to report a net loss for its second quarter ended March 26 and doesn't expect to meet analysts' profit estimates of $3.0 to $4 million, or 1,276 cents a share to 1,279 cents a share, for its year ending Sept. 24. (From the Wall Street Journal (1988))")
#to print sentences
@vinimonteiro
vinimonteiro / cos_sim.py
Created October 13, 2021 14:18
cos similarity example
from sklearn.metrics.pairwise import cosine_similarity
import pandas as pd
basetext = """
Quantum computers encode information in 0s and 1s at the same time, until you "measure" it
"""
text1 = """
A qubit stores "0 and 1 at the same time" in the same way how a car travelling north-west travels north and west at the same time
"""
text2 = """
@vinimonteiro
vinimonteiro / linear_regression.py
Created August 4, 2021 19:17
Linear regression algorithm from Pragramatic programmers
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
def predict(X, w, b):
return X * w + b
def loss(X, Y, w, b):
return np.average((predict(X, w, b) - Y) ** 2)
@vinimonteiro
vinimonteiro / generator_large_file.py
Created April 16, 2021 15:30
generator_large_file
def gen_file_reader(file_path):
for row in open(file_path, "r"):
yield row
def gen_print_row_count():
count = 0
for row in gen_file_reader("large_file"):
count += 1
print(f"Total count is {count}")
@vinimonteiro
vinimonteiro / run_function_large_file.py
Created April 16, 2021 15:27
run function large file
$ python large_file_example.py
Total count is 72456321
@vinimonteiro
vinimonteiro / function_large_file.py
Created April 16, 2021 15:25
Row count large file with function
def file_reader(file_path):
rows = []
for row in open(file_path, "r"):
rows.append(row)
return rows
def print_row_count():
count = 0
for row in file_reader("large_file"):
count += 1
@vinimonteiro
vinimonteiro / hello_world_from_file.py
Created April 14, 2021 19:45
Python Hello World From File
$ python /Users/viniciusmonteiro/hello_world.py
Hello World
$
@vinimonteiro
vinimonteiro / hello_world.py
Created April 14, 2021 19:33
Hello World in Python
$ python
>>> print('Hello World')
Hello World
>>>
@vinimonteiro
vinimonteiro / int_python3
Created February 7, 2021 08:52
int in Python 3
>>> print(923125123133123123163123193133193122123923123177 + 5)
923125123133123123163123193133193122123923123182