Skip to content

Instantly share code, notes, and snippets.

@Z4HRA-S
Z4HRA-S / profiler.py
Created July 16, 2021 07:20
Here is a module for profiling CPU and memory usage in python.The CumulativeProfile class is used as a decorator for monitoring CPU Consumption and RAM Utilization of a function.
from datetime import datetime
import cProfile
import time
import logging
import multiprocessing as mp
import psutil
class CumulativeProfile:
def __init__(self, func, v=0):
self.__name__ = func.__name__
@Z4HRA-S
Z4HRA-S / test_example1.py
Last active August 19, 2022 21:01
test_example1
from models import SaleRecords
from sqlalchemy import func
def sold_product_percent(session) -> dict:
sold_product = session.query(func.sum(SaleRecords.count), SaleRecords.product_name
).group_by(SaleRecords.product_name).all()
sum_of_products = sum(count for count, name in sold_product)
percents = {item[1]: round((item[0] / sum_of_products) * 100, 2)
for item in sold_product}
def test_decoupled_sold_product_percent(self):
# Arrange
session = mock.Mock()
session.query.return_value = session
session.filter.return_value = session
session.where.return_value = session
session.group_by.return_value = session
session.all.return_value = [(76, 'cheese_cake'),
(67, 'chocolate_cake'),
(70, 'coffee'),
class TestMain(unittest.TestCase):
def test_sold_product_percent(self):
# Arrange
session = mock.Mock()
session.query().group_by().all.return_value = [(76, 'cheese_cake'),
(67, 'chocolate_cake'),
(70, 'coffee'),
(17, 'hot_dog'),
(70, 'tea')]
@Z4HRA-S
Z4HRA-S / Thesis_summary.md
Created April 15, 2023 13:27
Thesis Summary

Thesis Summary

The task of relation extraction focuses on finding relational information between entities in a text. The input text can be one sentence or a document. Relational facts are highly semantic information that needs reasoning skills to discover. Therefore, the model must be capable of processing the text's semantic concepts. In this thesis, we explored the potential of the Caps-net in extracting high-level semantic information, capturing the relational information from the text, and the ability to overcome the imbalance problem of the data set. Our dataset was a complex data set with a severe imbalance and a relatively large number of potential entity-pair per document. The large number of entity pairs along with the complexity needed for solving this task, make the whole proposed model computationally expensive. In addition to trying to improve the model's performance on the dataset, we tried to reduce the memory and time complexity of the proposed model. In this work, we studied the Caps-Net [