Skip to content

Commit

Permalink
Add pip packacke support
Browse files Browse the repository at this point in the history
  • Loading branch information
movabo committed Dec 8, 2021
1 parent 24d2d34 commit 6054fd1
Show file tree
Hide file tree
Showing 112 changed files with 314 additions and 214 deletions.
5 changes: 4 additions & 1 deletion .idea/NewsMTSC.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
4 changes: 2 additions & 2 deletions DatasetPreparer.py → DeepNewsSentiment/DatasetPreparer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import jsonlines
from tabulate import tabulate

from SentimentClasses import SentimentClasses
from fxlogger import get_logger
from DeepNewsSentiment.SentimentClasses import SentimentClasses
from DeepNewsSentiment.fxlogger import get_logger


class DatasetPreparer:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions DeepNewsSentiment/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import argparse

from DeepNewsSentiment.download import Download

if __name__ == '__main__':
parser = argparse.ArgumentParser(prog='DeepNewsAnalysis')
subparsers = parser.add_subparsers(dest='action')

subparser_download = subparsers.add_parser('download', help=Download.add_subparser.__doc__)
Download.add_subparser(subparser_download)

args = parser.parse_args()
action = args.action
del args.action

if action == 'download':
Download.run_from_parser(args)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from consts import BERT_BASE_UNCASED
from DeepNewsSentiment.consts import BERT_BASE_UNCASED

combinations_default_0 = {
"own_model_name": [
Expand Down
File renamed without changes.
36 changes: 18 additions & 18 deletions controller.py → DeepNewsSentiment/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@
from tabulate import tabulate
from tqdm import tqdm

from combinations_ensemble import combinations_ensemble
from combinations_final_lcf2 import combinations_final_lcf2
from combinations_final_nostance import combinations_final_nostance
from combinations_final_spc import combinations_final_spc
from combinations_final_stance0 import combinations_final_stance0
from combinations_final_stance1 import combinations_final_stance1
from combinations_final_tdbert import combinations_final_tdbert
from combinations_top import combinations_top
from DatasetPreparer import DatasetPreparer
from combinations_default import combinations_default_0
from combinations_top4otherdomains import combinations_top4otherdomains
from combinations_top_coref16 import combinations_top_coref16
from combinations_top_coref8 import combinations_top_coref8
from combinations_top_coref8_stanceno import combinations_top_coref8_stanceno
from combinations_top_finetuned import combinations_top_finetuned
from diskdict import DiskDict
from fxlogger import get_logger
from train import str2bool
from DeepNewsSentiment.combinations_ensemble import combinations_ensemble
from DeepNewsSentiment.combinations_final_lcf2 import combinations_final_lcf2
from DeepNewsSentiment.combinations_final_nostance import combinations_final_nostance
from DeepNewsSentiment.combinations_final_spc import combinations_final_spc
from DeepNewsSentiment.combinations_final_stance0 import combinations_final_stance0
from DeepNewsSentiment.combinations_final_stance1 import combinations_final_stance1
from DeepNewsSentiment.combinations_final_tdbert import combinations_final_tdbert
from DeepNewsSentiment.combinations_top import combinations_top
from DeepNewsSentiment.DatasetPreparer import DatasetPreparer
from DeepNewsSentiment.combinations_default import combinations_default_0
from DeepNewsSentiment.combinations_top4otherdomains import combinations_top4otherdomains
from DeepNewsSentiment.combinations_top_coref16 import combinations_top_coref16
from DeepNewsSentiment.combinations_top_coref8 import combinations_top_coref8
from DeepNewsSentiment.combinations_top_coref8_stanceno import combinations_top_coref8_stanceno
from DeepNewsSentiment.combinations_top_finetuned import combinations_top_finetuned
from DeepNewsSentiment.diskdict import DiskDict
from DeepNewsSentiment.fxlogger import get_logger
from DeepNewsSentiment.train import str2bool

completed_tasks = None # will be DiskDict later
completed_tasks_in_this_run_count = 0
Expand Down
2 changes: 1 addition & 1 deletion createoverview.py → DeepNewsSentiment/createoverview.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import jsonlines
import pandas as pd

from fxlogger import get_logger
from DeepNewsSentiment.fxlogger import get_logger

logger = get_logger()

Expand Down
File renamed without changes.
18 changes: 9 additions & 9 deletions dataset.py → DeepNewsSentiment/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@
AlbertTokenizer,
)

from SentimentClasses import SentimentClasses
from customexceptions import TooLongTextException, TargetNotFoundException
from consts import *
from fxlogger import get_logger
from DeepNewsSentiment.SentimentClasses import SentimentClasses
from DeepNewsSentiment.customexceptions import TooLongTextException, TargetNotFoundException
from DeepNewsSentiment.consts import *
from DeepNewsSentiment.fxlogger import get_logger

# get logger
from knowledge.bingliuopinion.bingliuopinion import (
from DeepNewsSentiment.knowledge.bingliuopinion.bingliuopinion import (
get_bingliu_polarities_as_tensor,
get_num_bingliu_polarities,
)
from knowledge.mpqasubjectivity.mpqasubjectivity import (
from DeepNewsSentiment.knowledge.mpqasubjectivity.mpqasubjectivity import (
get_mpqa_subjectivity_polarities_as_tensor,
get_num_mpqa_subjectivity_polarities,
)
from knowledge.nrcemolex.nrcemolex import (
from DeepNewsSentiment.knowledge.nrcemolex.nrcemolex import (
get_nrc_emotions_as_tensor,
get_num_nrc_emotions,
)
from knowledge.zeros.zerosknowledge import get_num_zero_dimensions, get_zeros_as_tensor
from models.FXBaseModel import FXBaseModel
from DeepNewsSentiment.knowledge.zeros.zerosknowledge import get_num_zero_dimensions, get_zeros_as_tensor
from DeepNewsSentiment.models.FXBaseModel import FXBaseModel

logger = get_logger()
nlp = spacy.load("en_core_web_sm")
Expand Down
3 changes: 2 additions & 1 deletion diskdict.py → DeepNewsSentiment/diskdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import pickle
from typing import Union

from fxlogger import get_logger
from DeepNewsSentiment.fxlogger import get_logger

logger = get_logger()


class DiskDict(dict):
def __init__(self, sync_path: Union[Path, str]):
if type(sync_path) == str:
Expand Down
33 changes: 13 additions & 20 deletions download.py → DeepNewsSentiment/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import torch

from fxlogger import get_logger
from DeepNewsSentiment.fxlogger import get_logger


class Download:
Expand All @@ -19,8 +19,8 @@ class Download:
def __init__(
self, own_model_name, version="default", force=False, list_versions=False
):
from models.FXBaseModel import model_includes_pretrained
from train import OWN_MODELNAME2CLASS
from DeepNewsSentiment.models.FXBaseModel import model_includes_pretrained
from DeepNewsSentiment.train import OWN_MODELNAME2CLASS

logger = get_logger()
own_model_name = own_model_name
Expand Down Expand Up @@ -62,6 +62,7 @@ def download(cls, model_cls, version=None, force=False):
print("Model file already exists. Use --force to overwrite.")
exit(2)
print(f"Downloading to {path}:")
os.makedirs(os.path.dirname(path), exist_ok=True)
torch.hub.download_url_to_file(source, path)

@staticmethod
Expand All @@ -78,37 +79,29 @@ def model_path(cls, model_cls, version=None):
return os.path.join(cls.MODEL_DIRECTORY, cls.model_filename(model_cls, version))

@staticmethod
def argument_parser():
parser = argparse.ArgumentParser()
parser.add_argument("--own_model_name", default="grutsc", type=str)
parser.add_argument(
def add_subparser(subparser):
"""Download models for DeepNewsSentiment"""
subparser.add_argument("--own_model_name", default="grutsc", type=str)
subparser.add_argument(
"--version",
default=None,
type=str,
help="version of the model to download, use --force to overwrite a version which was already downloaded",
)
parser.add_argument(
subparser.add_argument(
"--force",
action="store_true",
help="force the download of a model and overwrite potential previous versions",
)
parser.add_argument(
subparser.add_argument(
"--list_versions",
action="store_true",
help="List all pretrained model versions which a model provides",
)
return parser
return subparser

@classmethod
def run_from_cmd(cls):
args = vars(cls.argument_parser().parse_args())
def run_from_parser(cls, args_namespace):
args = vars(args_namespace)
return cls(**args)

@classmethod
def run_defaults(cls):
args = vars(cls.argument_parser().parse_args([]))
return cls(**args)


if __name__ == "__main__":
Download.run_from_cmd()
2 changes: 1 addition & 1 deletion earlystopping.py → DeepNewsSentiment/earlystopping.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright by Bjarten
# License: MIT

from fxlogger import get_logger
from DeepNewsSentiment.fxlogger import get_logger


class EarlyStopping:
Expand Down
6 changes: 3 additions & 3 deletions evaluator.py → DeepNewsSentiment/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import numpy as np
from sklearn import metrics

from SentimentClasses import SentimentClasses
from dataset import FXDataset
from fxlogger import get_logger
from DeepNewsSentiment.SentimentClasses import SentimentClasses
from DeepNewsSentiment.dataset import FXDataset
from DeepNewsSentiment.fxlogger import get_logger


class Evaluator:
Expand Down
5 changes: 3 additions & 2 deletions fxlogger.py → DeepNewsSentiment/fxlogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ def get_logger():
handler = logging.StreamHandler()
handler.setFormatter(formatter)

logger = logging.getLogger("root")
logger.setLevel(logging.INFO)
logger = logging.getLogger("DeepNewsSentiment")
if logger.level == logging.NOTSET:
logger.setLevel(logging.INFO)

if len(logger.handlers) == 0:
logger.addHandler(handler)
Expand Down
1 change: 1 addition & 0 deletions DeepNewsSentiment/hubconf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from DeepNewsSentiment.models.singletarget.grutscsingle import GRUTSCSingle
12 changes: 6 additions & 6 deletions infer.py → DeepNewsSentiment/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from jsonlines import jsonlines
from tqdm import tqdm

from SentimentClasses import SentimentClasses
from dataset import FXEasyTokenizer
from download import Download
from fxlogger import get_logger
from models.singletarget.grutscsingle import GRUTSCSingle
from train import (
from DeepNewsSentiment.SentimentClasses import SentimentClasses
from DeepNewsSentiment.dataset import FXEasyTokenizer
from DeepNewsSentiment.download import Download
from DeepNewsSentiment.fxlogger import get_logger
from DeepNewsSentiment.models.singletarget.grutscsingle import GRUTSCSingle
from DeepNewsSentiment.train import (
parse_arguments as parse_arguments_from_train,
prepare_and_start_instructor,
)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from diskdict import DiskDict
import torch

from knowledge.bingliuopinion.converter import PATH_DICT_BING_LIU_OPINION_POLARITY, POLARITY2INDEX
from knowledge.knowledgeutils import find_key_original_or_lc
from DeepNewsSentiment.diskdict import DiskDict
from DeepNewsSentiment.knowledge.bingliuopinion.converter import PATH_DICT_BING_LIU_OPINION_POLARITY, POLARITY2INDEX
from DeepNewsSentiment.knowledge.knowledgeutils import find_key_original_or_lc

__ddict_emolex = DiskDict(PATH_DICT_BING_LIU_OPINION_POLARITY)
__ddict_emolex_keys_lower = {k.lower(): v for k, v in __ddict_emolex.items()}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from collections import defaultdict, Counter
from pathlib import Path
import csv
import os

from tqdm import tqdm

from fxlogger import get_logger
from diskdict import DiskDict
from DeepNewsSentiment.fxlogger import get_logger
from DeepNewsSentiment.diskdict import DiskDict

POLARITY2INDEX = {
"positive": 1,
"negative": 0,
}
PATH_DICT_BING_LIU_OPINION_POLARITY = Path(
"knowledge/bingliuopinion/opinion_polarity.ddict"
)
THIS_DIR = Path(os.path.dirname(os.path.realpath(__file__)))
PATH_DICT_BING_LIU_OPINION_POLARITY = THIS_DIR / "opinion_polarity.ddict"

logger = get_logger()

Expand All @@ -30,9 +30,8 @@ def convert_single_txt_to_dict(path: Path):


def convert_txt_to_dict():
path_dict = Path("knowledge/bingliuopinion/")
path_pos = path_dict / "positive-words.txt"
path_neg = path_dict / "negative-words.txt"
path_pos = THIS_DIR / "positive-words.txt"
path_neg = THIS_DIR / "negative-words.txt"

term2polarity = defaultdict(set)
polarity_counter = Counter()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import torch

from knowledge.liwc.liwchelper import load_token_parser
from DeepNewsSentiment.knowledge.liwc.liwchelper import load_token_parser

parse, category_names = load_token_parser()

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import os
from collections import defaultdict, Counter
from pathlib import Path
import csv

from tqdm import tqdm

from fxlogger import get_logger
from diskdict import DiskDict
from DeepNewsSentiment.fxlogger import get_logger
from DeepNewsSentiment.diskdict import DiskDict

POLARITY2INDEX = {
"positive": 2,
"neutral": 1,
"negative": 0,
}
PATH_DICT_MPQA_SUBJECTIVITY = Path(
"knowledge/mpqasubjectivity/subjclueslen1-HLTEMNLP05.tff.ddict"
)
THIS_DIR = Path(os.path.dirname(os.path.realpath(__file__)))
PATH_DICT_MPQA_SUBJECTIVITY = THIS_DIR / "subjclueslen1-HLTEMNLP05.tff.ddict"

logger = get_logger()

Expand All @@ -24,7 +24,7 @@ def get_value(entry_key_value: str):


def convert_txt_to_dict():
path_dict = Path("knowledge/mpqasubjectivity/subjclueslen1-HLTEMNLP05.tff")
path_dict = THIS_DIR / "subjclueslen1-HLTEMNLP05.tff"

term2polarity = defaultdict(set)
polarity_counter = Counter()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from diskdict import DiskDict
import torch

from knowledge.knowledgeutils import find_key_original_or_lc
from knowledge.mpqasubjectivity.converter import POLARITY2INDEX, PATH_DICT_MPQA_SUBJECTIVITY
from DeepNewsSentiment.diskdict import DiskDict
from DeepNewsSentiment.knowledge.knowledgeutils import find_key_original_or_lc
from DeepNewsSentiment.knowledge.mpqasubjectivity.converter import POLARITY2INDEX, PATH_DICT_MPQA_SUBJECTIVITY

__ddict_emolex = DiskDict(PATH_DICT_MPQA_SUBJECTIVITY)
__ddict_emolex_keys_lower = {k.lower(): v for k, v in __ddict_emolex.items()}
Expand Down
Loading

0 comments on commit 6054fd1

Please sign in to comment.