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 [
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
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')] |
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
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'), |
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
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} |
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
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__ |