Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed type hint and added example of label vector for build_word_frequency method #198

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/htwgnlp/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from collections import defaultdict

import numpy as np
import numpy.typing as npt


class CountVectorizer:
Expand All @@ -31,12 +32,13 @@ def __init__(self):
raise NotImplementedError("This method needs to be implemented.")

def build_word_frequencies(
self, tweets: list[list[str]], labels: np.ndarray
self, tweets: list[list[str]], labels: npt.NDArray[np.int_]
) -> None:
"""Builds a dictionary of word frequencies by counting the number of occurrences of each word in each class.

The key is a tuple of the word and the class, the value is the frequency of the word in the class.
For example, the key ('happi', 1) refers to the word 'happi' in the positive class,
while ('happi', 0) refers to 'happi' in the negative class,
and the value it holds is the number of times the word 'happi' occurs in the positive class.

Example:
Expand All @@ -47,8 +49,7 @@ def build_word_frequencies(

Args:
tweets (list[list[str]]): a list of tokenized tweets
labels (list[str]): a list of corresponding class labels

labels (npt.NDArray[np.int_]): a column vector of corresponding class labels , e.g. `np.array([[1], [0], [1], [0]]`)
"""
# TODO ASSIGNMENT-2: implement this method
raise NotImplementedError("This method needs to be implemented.")
Expand Down
Loading