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

A Classification Example in Forte Pipeline using CNN Classifier and Bert Classifier #336

Open
wants to merge 57 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
c575f12
LZQ:Add Classification Task__CNN
ziqian98 Dec 11, 2020
aac73a6
LZQ: Reader and Reader Test
ziqian98 Dec 11, 2020
c9a4771
LZQ:Update main train
ziqian98 Dec 11, 2020
ff24adc
LZQ:Update CNN model
ziqian98 Dec 11, 2020
9b28b8d
LZQ: Update minor bugs in main train
ziqian98 Dec 11, 2020
f2acf1a
LZQ: Update minor bugs in main predict
ziqian98 Dec 11, 2020
b74d77c
LZQ: Update for minor changes
ziqian98 Dec 16, 2020
9ae5fb4
LZQ: update minor changes in main_train
ziqian98 Dec 16, 2020
a73d7e6
LZQ: Add Bert in Classification Task
ziqian98 Dec 16, 2020
3b215e9
LZQ: Add Bert in Classification Prediction
ziqian98 Dec 16, 2020
7480e5a
LZQ: Merge data augmentation feature with main_train_cnn
ziqian98 Dec 16, 2020
83cbea7
LZQ: Add reader for merging data_augmentation feature
ziqian98 Dec 16, 2020
456f66d
Merge branch 'master' into lzq_new_classification
hunterhector Dec 17, 2020
7ccffee
Reform main train
ziqian98 Dec 19, 2020
9b8d1aa
LZQ: Reform redaer
ziqian98 Dec 20, 2020
7f560d7
LZQ: Delete old files
ziqian98 Dec 20, 2020
9ba6808
LZQ: Delete old augmentation reader
ziqian98 Dec 20, 2020
cad9fb7
LZQ: Upload imdb data samples to lzq_new_classification
ziqian98 Dec 20, 2020
63740ec
LZQ: Format
ziqian98 Dec 20, 2020
7830f81
LZQ: Format
ziqian98 Dec 20, 2020
d1cac8d
LZQ: Format main_train
ziqian98 Dec 20, 2020
92354a0
LZQ: Add Classification Data
ziqian98 Dec 20, 2020
fe70efc
LZQ: Add config_data yml file
ziqian98 Dec 20, 2020
c2efe83
LZQ: Add config model yml file
ziqian98 Dec 20, 2020
8897bdc
LZQ: Add config predict yml
ziqian98 Dec 20, 2020
a116684
LZQ: Add cnn model
ziqian98 Dec 20, 2020
2b9bc33
LZQ: Add prediction
ziqian98 Dec 20, 2020
04b0992
LZQ: Add utilility function
ziqian98 Dec 20, 2020
1ccd9b1
LZQ: Format cnn
ziqian98 Dec 20, 2020
e91633d
LZQ: Format main predict
ziqian98 Dec 20, 2020
f0d09df
LZQ: Format util
ziqian98 Dec 20, 2020
fd5141c
LZQ: Format cnn
ziqian98 Dec 20, 2020
ff779c8
LZQ: format CNN
ziqian98 Dec 20, 2020
acaf94e
LZQ: Format IMDB Reader
ziqian98 Dec 20, 2020
87a8bd5
LZQ: Format imdb reader
ziqian98 Dec 20, 2020
37f9b4d
LZQ: Format imdb reader
ziqian98 Dec 20, 2020
80fbef4
LZQ: Modify inputs of collect in reader
ziqian98 Dec 20, 2020
084f841
LZQ: Format reader
ziqian98 Dec 21, 2020
5c7e7a0
LZQ: Add Readme file
ziqian98 Dec 21, 2020
7d18628
LZQ: Update Train
ziqian98 Jan 5, 2021
d905307
LZQ: Fix label prediction problems
ziqian98 Jan 6, 2021
2ae2621
LZQ: Add testing accuracy
ziqian98 Jan 6, 2021
e6f3aea
LZQ: train format
ziqian98 Jan 6, 2021
dc45084
LZQ: update predict
ziqian98 Jan 6, 2021
a6e2388
LZQ: Reader for new API
ziqian98 Jan 10, 2021
2b5da59
LZQ: update train for new API
ziqian98 Jan 10, 2021
f19a07b
LZQ: Format train for new API
ziqian98 Jan 10, 2021
ab56bb2
LZQ: update reader test for new API
ziqian98 Jan 10, 2021
8eba3c0
LZQ: Format train
ziqian98 Jan 12, 2021
08bb2ad
LZQ: Format model cnn
ziqian98 Jan 12, 2021
045bdda
LZQ: Format main train
ziqian98 Jan 12, 2021
3b4b10e
LZQ: Remove a util function
ziqian98 Jan 12, 2021
692faa3
Reform the extractor and add mask
ziqian98 Jan 12, 2021
1f94612
LZQ: both pisitvie and negetavie keys are contained
ziqian98 Jan 12, 2021
75c5ab6
LZQ: Update for sentiment dictionary keys
ziqian98 Jan 12, 2021
59d6464
LZQ: change the way of adding data aug processor
ziqian98 Jan 12, 2021
bcaf655
LZQ: Add a data_aug flag
ziqian98 Jan 12, 2021
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
6 changes: 6 additions & 0 deletions data_samples/imdb/sample.imdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"One of the other reviewers has mentioned that after watching just 1 Oz episode you'll be hooked. They are right, as this is exactly what happened with me.<br /><br />The first thing that struck me about Oz was its brutality and unflinching scenes of violence, which set in right from the word GO. Trust me, this is not a show for the faint hearted or timid. This show pulls no punches with regards to drugs, sex or violence. Its is hardcore, in the classic use of the word.<br /><br />It is called OZ as that is the nickname given to the Oswald Maximum Security State Penitentary. It focuses mainly on Emerald City, an experimental section of the prison where all the cells have glass fronts and face inwards, so privacy is not high on the agenda. Em City is home to many..Aryans, Muslims, gangstas, Latinos, Christians, Italians, Irish and more....so scuffles, death stares, dodgy dealings and shady agreements are never far away.<br /><br />I would say the main appeal of the show is due to the fact that it goes where other shows wouldn't dare. Forget pretty pictures painted for mainstream audiences, forget charm, forget romance...OZ doesn't mess around. The first episode I ever saw struck me as so nasty it was surreal, I couldn't say I was ready for it, but as I watched more, I developed a taste for Oz, and got accustomed to the high levels of graphic violence. Not just violence, but injustice (crooked guards who'll be sold out for a nickel, inmates who'll kill on order and get away with it, well mannered, middle class inmates being turned into prison bitches due to their lack of street skills or prison experience) Watching Oz, you may become comfortable with what is uncomfortable viewing....thats if you can get in touch with your darker side.",negative
"A wonderful little production. <br /><br />The filming technique is very unassuming- very old-time-BBC fashion and gives a comforting, and sometimes discomforting, sense of realism to the entire piece. <br /><br />The actors are extremely well chosen- Michael Sheen not only ""has got all the polari"" but he has all the voices down pat too! You can truly see the seamless editing guided by the references to Williams' diary entries, not only is it well worth the watching but it is a terrificly written and performed piece. A masterful production about one of the great master's of comedy and his life. <br /><br />The realism really comes home with the little things: the fantasy of the guard which, rather than use the traditional 'dream' techniques remains solid then disappears. It plays on our knowledge and our senses, particularly with the scenes concerning Orton and Halliwell and the sets (particularly of their flat with Halliwell's murals decorating every surface) are terribly well done.",positive
"I thought this was a wonderful way to spend time on a too hot summer weekend, sitting in the air conditioned theater and watching a light-hearted comedy. The plot is simplistic, but the dialogue is witty and the characters are likable (even the well bread suspected serial killer). While some may be disappointed when they realize this is not Match Point 2: Risk Addiction, I thought it was proof that Woody Allen is still fully in control of the style many of us have grown to love.<br /><br />This was the most I'd laughed at one of Woody's comedies in years (dare I say a decade?). While I've never been impressed with Scarlet Johanson, in this she managed to tone down her ""sexy"" image and jumped right into a average, but spirited young woman.<br /><br />This may not be the crown jewel of his career, but it was wittier than ""Devil Wears Prada"" and more interesting than ""Superman"" a great comedy to go see with friends.",positive
"Basically there's a family where a little boy (Jake) thinks there's a zombie in his closet & his parents are fighting all the time.<br /><br />This movie is slower than a soap opera... and suddenly, Jake decides to become Rambo and kill the zombie.<br /><br />OK, first of all when you're going to make a film you must Decide if its a thriller or a drama! As a drama the movie is watchable. Parents are divorcing & arguing like in real life. And then we have Jake with his closet which totally ruins all the film! I expected to see a BOOGEYMAN similar movie, and instead i watched a drama with some meaningless thriller spots.<br /><br />3 out of 10 just for the well playing parents & descent dialogs. As for the shots with Jake: just ignore them.",positive
"Petter Mattei's ""Love in the Time of Money"" is a visually stunning film to watch. Mr. Mattei offers us a vivid portrait about human relations. This is a movie that seems to be telling us what money, power and success do to people in the different situations we encounter. <br /><br />This being a variation on the Arthur Schnitzler's play about the same theme, the director transfers the action to the present time New York where all these different characters meet and connect. Each one is connected in one way, or another to the next person, but no one seems to know the previous point of contact. Stylishly, the film has a sophisticated luxurious look. We are taken to see how these people live and the world they live in their own habitat.<br /><br />The only thing one gets out of all these souls in the picture is the different stages of loneliness each one inhabits. A big city is not exactly the best place in which human relations find sincere fulfillment, as one discerns is the case with most of the people we encounter.<br /><br />The acting is good under Mr. Mattei's direction. Steve Buscemi, Rosario Dawson, Carol Kane, Michael Imperioli, Adrian Grenier, and the rest of the talented cast, make these characters come alive.<br /><br />We wish Mr. Mattei good luck and await anxiously for his next work.",positive
"Probably my all-time favorite movie, a story of selflessness, sacrifice and dedication to a noble cause, but it's not preachy or boring. It just never gets old, despite my having seen it some 15 or more times in the last 25 years. Paul Lukas' performance brings tears to my eyes, and Bette Davis, in one of her very few truly sympathetic roles, is a delight. The kids are, as grandma says, more like ""dressed-up midgets"" than children, but that only makes them more fun to watch. And the mother's slow awakening to what's happening in the world and under her own roof is believable and startling. If I had a dozen thumbs, they'd all be ""up"" for this movie.",positive
28 changes: 28 additions & 0 deletions examples/classification_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Sentence Sentiment Classifier

This is a Sentence Sentiment Classifier as an example of Classification Task

The example contains two classifier, Conv Classifier and Bert Classifier

The example shows:
* Training and predicting pipeline using Forte
* How to write a reader for [IMDB dataset](https://www.kaggle.com/lakshmi25npathi/imdb-dataset-of-50k-movie-reviews)
* How to set configuration in Train Preprocessor
* How to switch Classifier from CNN to Bert
* How to add data augmentation
Copy link
Member

Choose a reason for hiding this comment

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

This is not here yet?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You mean the data augmentation?

Copy link
Member

Choose a reason for hiding this comment

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

yes


# Usage
Use the following to train the network:
```
python main_train.py
```
Use the following to train the network:
```
python main_predict.py
```

If you want to switch model from CNN to Bert, set the "model" field in [config_model.yml](./config_model.yml)

You can also define your own classifier or network in another python file like [cnn.py](./cnn.py) here

Define you utility function in [util.py](./util.py)
Copy link
Member

Choose a reason for hiding this comment

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

This line can be removed. Users can define their utilities if they want.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"One of the other reviewers has mentioned that after watching just 1 Oz episode you'll be hooked. They are right, as this is exactly what happened with me.<br /><br />The first thing that struck me about Oz was its brutality and unflinching scenes of violence, which set in right from the word GO. Trust me, this is not a show for the faint hearted or timid. This show pulls no punches with regards to drugs, sex or violence. Its is hardcore, in the classic use of the word.<br /><br />It is called OZ as that is the nickname given to the Oswald Maximum Security State Penitentary. It focuses mainly on Emerald City, an experimental section of the prison where all the cells have glass fronts and face inwards, so privacy is not high on the agenda. Em City is home to many..Aryans, Muslims, gangstas, Latinos, Christians, Italians, Irish and more....so scuffles, death stares, dodgy dealings and shady agreements are never far away.<br /><br />I would say the main appeal of the show is due to the fact that it goes where other shows wouldn't dare. Forget pretty pictures painted for mainstream audiences, forget charm, forget romance...OZ doesn't mess around. The first episode I ever saw struck me as so nasty it was surreal, I couldn't say I was ready for it, but as I watched more, I developed a taste for Oz, and got accustomed to the high levels of graphic violence. Not just violence, but injustice (crooked guards who'll be sold out for a nickel, inmates who'll kill on order and get away with it, well mannered, middle class inmates being turned into prison bitches due to their lack of street skills or prison experience) Watching Oz, you may become comfortable with what is uncomfortable viewing....thats if you can get in touch with your darker side.",negative
"A wonderful little production. <br /><br />The filming technique is very unassuming- very old-time-BBC fashion and gives a comforting, and sometimes discomforting, sense of realism to the entire piece. <br /><br />The actors are extremely well chosen- Michael Sheen not only ""has got all the polari"" but he has all the voices down pat too! You can truly see the seamless editing guided by the references to Williams' diary entries, not only is it well worth the watching but it is a terrificly written and performed piece. A masterful production about one of the great master's of comedy and his life. <br /><br />The realism really comes home with the little things: the fantasy of the guard which, rather than use the traditional 'dream' techniques remains solid then disappears. It plays on our knowledge and our senses, particularly with the scenes concerning Orton and Halliwell and the sets (particularly of their flat with Halliwell's murals decorating every surface) are terribly well done.",positive
"I thought this was a wonderful way to spend time on a too hot summer weekend, sitting in the air conditioned theater and watching a light-hearted comedy. The plot is simplistic, but the dialogue is witty and the characters are likable (even the well bread suspected serial killer). While some may be disappointed when they realize this is not Match Point 2: Risk Addiction, I thought it was proof that Woody Allen is still fully in control of the style many of us have grown to love.<br /><br />This was the most I'd laughed at one of Woody's comedies in years (dare I say a decade?). While I've never been impressed with Scarlet Johanson, in this she managed to tone down her ""sexy"" image and jumped right into a average, but spirited young woman.<br /><br />This may not be the crown jewel of his career, but it was wittier than ""Devil Wears Prada"" and more interesting than ""Superman"" a great comedy to go see with friends.",positive
"Basically there's a family where a little boy (Jake) thinks there's a zombie in his closet & his parents are fighting all the time.<br /><br />This movie is slower than a soap opera... and suddenly, Jake decides to become Rambo and kill the zombie.<br /><br />OK, first of all when you're going to make a film you must Decide if its a thriller or a drama! As a drama the movie is watchable. Parents are divorcing & arguing like in real life. And then we have Jake with his closet which totally ruins all the film! I expected to see a BOOGEYMAN similar movie, and instead i watched a drama with some meaningless thriller spots.<br /><br />3 out of 10 just for the well playing parents & descent dialogs. As for the shots with Jake: just ignore them.",positive
"Petter Mattei's ""Love in the Time of Money"" is a visually stunning film to watch. Mr. Mattei offers us a vivid portrait about human relations. This is a movie that seems to be telling us what money, power and success do to people in the different situations we encounter. <br /><br />This being a variation on the Arthur Schnitzler's play about the same theme, the director transfers the action to the present time New York where all these different characters meet and connect. Each one is connected in one way, or another to the next person, but no one seems to know the previous point of contact. Stylishly, the film has a sophisticated luxurious look. We are taken to see how these people live and the world they live in their own habitat.<br /><br />The only thing one gets out of all these souls in the picture is the different stages of loneliness each one inhabits. A big city is not exactly the best place in which human relations find sincere fulfillment, as one discerns is the case with most of the people we encounter.<br /><br />The acting is good under Mr. Mattei's direction. Steve Buscemi, Rosario Dawson, Carol Kane, Michael Imperioli, Adrian Grenier, and the rest of the talented cast, make these characters come alive.<br /><br />We wish Mr. Mattei good luck and await anxiously for his next work.",positive
"Probably my all-time favorite movie, a story of selflessness, sacrifice and dedication to a noble cause, but it's not preachy or boring. It just never gets old, despite my having seen it some 15 or more times in the last 25 years. Paul Lukas' performance brings tears to my eyes, and Bette Davis, in one of her very few truly sympathetic roles, is a delight. The kids are, as grandma says, more like ""dressed-up midgets"" than children, but that only makes them more fun to watch. And the mother's slow awakening to what's happening in the world and under her own roof is believable and startling. If I had a dozen thumbs, they'd all be ""up"" for this movie.",positive
jasonyanwenl marked this conversation as resolved.
Show resolved Hide resolved
Loading