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

[#3] 입력 데이터를 처리하기 위한 namedtuple 구현 #6

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

22ema
Copy link
Collaborator

@22ema 22ema commented Oct 19, 2024

What is this PR 🔍

  • Sparse feature와 dense feature, 가변 sparse feature의 정보를 담기위한 namedtuple 클래스를 구현하였습니다.
  • Sparse feature
    • 단일 범주형 데이터의 info 저장 (범주형 데이터가 변환될 embedding 차원도 지정)
  • Dense feature
    • 수치형 데이터의 info 저장 (다차원의 데이터를 다룰수 있음)
  • VarLen Sparse feature
    • 여러개의 범주형 데이터의 info 저장 (Sparse feat 객체를 사용함)

Changes 🔑

  • inputs.py 내 SparseFeat, DenseFeat, VarLenSparseFeat 클래스 구현.

To Reviewer 🙇‍♂️

  • 각 클래스는 DeepCTR_torch 코드를 참조하여 작성하였습니다. 혹시 해당 코드에 부족한 점이 있다면 검토 부탁드립니다.
  • 18번 줄에 단순 print문으로 작성된 것을 예외처리문으로 변경하였는데, 괜찮을지 검토 부탁드립니다.

@22ema 22ema requested a review from f-lab-owen October 19, 2024 01:53
@22ema 22ema self-assigned this Oct 19, 2024
@22ema 22ema changed the title [feat_#3_1] 입력 데이터를 처리하기 위한 namedtuple 구현 [#3] 입력 데이터를 처리하기 위한 namedtuple 구현 Oct 19, 2024
Copy link
Collaborator

@f-lab-owen f-lab-owen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[공통 코멘트]

  • 파라미터에 대한 데이터형 힌트 추가 부탁드립니다
  • 모듈, 클래스, 함수에 대한 DocString 추가 부탁드립니다.

CATS/inputs.py Outdated
group_name=DEFAULT_GROUP_NAME):
if embedding_name is None:
embedding_name = name
elif embedding_name == 'auto':
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

embedding_name == 'auto'가 의도하신 부분이 맞으실까요? 해당 조건문 하위에서 동작하는 로직이 임베딩차원과 관련되어 보여서

elif embedding_dim == 'auto':

가 아닌가 해서요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 오타네요..ㅠ 수정하겠습니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오타 수정완료하였습니다. 212ec0d

CATS/inputs.py Outdated
'group_name'])):
__slots__ = ()

def __new__(cls, name, vocabulary_size, embedding_dim=4, use_hash=False, dtype="int32", embedding_name=None,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

함수의 param에 데이터형 힌트 추가 해주세요! 해당 함수(__new__)뿐만 아니라 모든 코드에 적용 부탁드립니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 모든코드에 적용하도록 하겠습니다. 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SparseFeat 클래스 내 new() 함수 param에 데이터형 힌트 추가 완료하였습니다. b08ff67

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VarLenSparseFeat 클래스 내 new()함수 param에 데이터형 힌트 추가 완료하였습니다. cb328a4

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DenseFeat 클래스 내 new()함수 param에 데이터형 힌트 추가 완료하였습니다. b77a4f4

class SparseFeat(namedtuple('SparseFeat',
['name', 'vocabulary_size', 'embedding_dim', 'use_hash', 'dtype', 'embedding_name',
'group_name'])):
__slots__ = ()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__slots__의 용처와 사용법이 어떻게 되는지 설명해 주실 수 있으실까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기존 클래스는 instance를 생성하면 dictionary에 키와 값을 저장합니다. dictionary를 사용했을 때, 장점은 멤버변수를 동적으로 추가하기 쉽다는 것입니다. 하지만 단점은 멤버변수가 동적이기 때문에 잘못된 멤버변수를 사용하여 오류가 날 수 있고 객체 마다 별도의 메모리를 관리해야하기 때문에 메모리 오버헤드가 큽니다.
__slots__는 __dict__와 다르게 static한 멤버변수를 가지기 때문에 고정된 메모리 공간을 사용하여 효율적인 메모리 관리가 가능합니다. 그렇기 때문에 객체 내 저장될 데이터의 수가 많다면 __slots__를 사용하여 객체를 관리하는 것이 효율적입니다.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

�그럼 nametuple 역시 불변 객체를 만드는데요. 명시적으로 __slots__()을 적어주신 추가적인 이유가 있으신지 궁금합니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__slots__를 ()로 선언하게되면 동적으로 속성값을 변경할 수 없게되며 메모리 효율이 증가합니다. 그렇기 때문에 현재 객체내 멤버변수값을 동적으로 바꿀 필요가 없는경우 메모리 효율을 위해 slots=()를 작성하였습니다.

CATS/inputs.py Outdated
['sparsefeat', 'maxlen', 'combiner', 'length_name'])):
__slots__ = ()

def __new__(cls, sparsefeat, maxlen, combiner="mean", length_name=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

combiner 종류를 str 형으로 되어 있어서, 사용자가 combiner로 사용 가능한 값이 어떤 것인지 인지하기 쉽지 않습니다. Enum 또는 Literal로 입력 가능한 값을 기정의하는 방식으로 처리하면 좋을 것 같습니다. (참고)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 수정하겠습니다.

CATS/inputs.py Outdated
Comment on lines 70 to 71
def __new__(cls, name, dimension=1, dtype="float32"):
return super(DenseFeat, cls).__new__(cls, name, dimension, dtype)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dimension 값에 대한 유효성 검증이 추가되면 좋겠습니다.

Suggested change
def __new__(cls, name, dimension=1, dtype="float32"):
return super(DenseFeat, cls).__new__(cls, name, dimension, dtype)
def __new__(cls, name, dimension=1, dtype="float32"):
if dimension < 0 and not isinstance(dimension, int):
raise ValueError(...)
return super(DenseFeat, cls).__new__(cls, name, dimension, dtype)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 수정하도록 하겠습니다.😄

@22ema
Copy link
Collaborator Author

22ema commented Oct 23, 2024

코멘트 달아주신 내용 수정하여 commit 하였습니다. 검토 부탁드립니다.🙏🏻

@f-lab-owen
Copy link
Collaborator

코멘트 달아주신 내용 수정하여 commit 하였습니다. 검토 부탁드립니다.🙏🏻

@22ema 몇가지 안내드릴 사항이 있어서 내일 멘토링 시간에 구두로 얘기드리도록 하겠습니다!

  • Resolve 주체와 기준
  • 커밋 단위
  • 수정요청 코멘트에 대한 처리 방식

@22ema
Copy link
Collaborator Author

22ema commented Oct 23, 2024

코멘트 달아주신 내용 수정하여 commit 하였습니다. 검토 부탁드립니다.🙏🏻

@22ema 몇가지 안내드릴 사항이 있어서 내일 멘토링 시간에 구두로 얘기드리도록 하겠습니다!

  • Resolve 주체와 기준
  • 커밋 단위
  • 수정요청 코멘트에 대한 처리 방식

넵!

DEFAULT_GROUP_NAME = "default_group"


class SparseFeat(namedtuple('SparseFeat',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

가이드를 드리기위한 코멘트 (임시)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants