Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- Absolute
- AGI
- ai
- AI agents
- AI engineer
- AI researcher
- ajax
- algorithm
- Algorithms
- aliases
- Array 객체
- ASI
- bayes' theorem
- Bit
- Blur
- BOM
- bootstrap
- canva
- challenges
- ChatGPT
Archives
- Today
- In Total
A Joyful AI Research Journey🌳😊
The use of the * unpacking operator 본문
The * in zip(*combined_dataset) is the "unpacking" operator in Python. It takes a list of tuples (in this case, combined_dataset, which consists of pairs like (review_text, label)) and "unzips" them into two separate tuples: one for texts and one for labels.
In other words:
- texts will contain all the review texts.
- labels will contain all the corresponding labels.
The * operator effectively transposes the list of tuples into separate lists (or tuples) for each component.
Here's an example to illustrate the use of the * unpacking operator:
Example Without Unpacking:
combined_dataset = [
("I love this movie!", 1),
("This movie was terrible.", 0),
("Amazing storyline!", 1)
]
texts, labels = zip(("I love this movie!", 1), ("This movie was terrible.", 0), ("Amazing storyline!", 1))
print(texts) # Output: ('I love this movie!', 'This movie was terrible.', 'Amazing storyline!')
print(labels) # Output: (1, 0, 1)
Example With Unpacking (*):
combined_dataset = [
("I love this movie!", 1),
("This movie was terrible.", 0),
("Amazing storyline!", 1)
]
texts, labels = zip(*combined_dataset)
print(texts) # Output: ('I love this movie!', 'This movie was terrible.', 'Amazing storyline!')
print(labels) # Output: (1, 0, 1)
Explanation:
- Without *: You have to manually provide each pair of values to zip.
- With *: The * operator unpacks the list of tuples into separate arguments for zip, automatically separating texts and labels.
728x90
반응형
'🌳AI Projects: NLP🍀✨ > NLP Deep Dive' 카테고리의 다른 글
The evaluation metric for text generation (4) | 2024.08.31 |
---|---|
Links to Python zip() Function (0) | 2024.08.25 |
Links to BERT base model (uncased) (0) | 2024.08.25 |
Naive Bayes versus BERT in Sentiment Analysis (0) | 2024.08.24 |
Comments