Python代写 | COMP9444 Assignment 2


COMP9444 Assignment 2
Term 2, 2020

For this assignment you will be writing a Pytorch program that learns to read product
reviews in text format and predict an integer rating from 1 to 5 stars associated with
each review.
Getting Started
Copy the archive into your own filespace and unzip it. This should create an
hw2 directory containing the main file , skeleton file and data
file train.json . Your task is to complete the file in such a way that it can
be run in conjunction with by typing
You must NOT modify in any way. You should ONLY modify
The provided file handles the following:
Loading the data from train.json
Splitting the data into training and validation sets (in the ratio specified by
trainValSplit )
Data Processing: strings are converted to lower case, and lengths of the reviews
are calculated and added to the dataset (this allows for dynamic padding). You can
optionally add your own preprocessing, postprocessing and stop_words (Note that
none of this is necessarily required, but it is possible).
Vectorization, using torchtext GloVe vectors 6B.
Batching, using the BucketIterator() prodived by torchtext so as to batch together
reviews of similar length. This is not necessary for accuracy but will speed up
training since the total sequence length can be reduced for some batches.
The code is structured to be backend-agnostic. That is, if a GPU is present, it will
automatically be used; otherwise, the CPU will be used. This is the purpose of the
.to(device) function being called on several operations. Please take some time to read
through and understand what it does.
We have tried to structure so as to allow as much flexibility as possible in
the design of your code. You are free to create additional variables,
functions, classes, etc., so long as your code runs correctly with
unmodified, and you are only using the approved packages. You must adhere to the
these constraints:
1. Your model must be defined in a class named network .
2. The savedModel.pth file you submit must be generated by the file
you submit.
3. Your submission (including savedModel.pth ) must be under 50MB and you
cannot load any external assets in the network class.
4. While you may train on a GPU, you must ensure your model is able to be
evaluated on a CPU.
The GloVe vectors are stored in a subdirectory called .vector_cache . You are
restricted to using GloVe vectors 6B, but you are free to specify the value of dim (50,
100, 200 or 300).
You must ensure that we can load your code and test it. This will involve importing your file, creating an instance of your network class, restoring the parameters
from your savedModel.pth , loading our own test dataset, processing according to what
you specified in your file, and calculating accuracy and score.
You may NOT download or load data other than what we have provided. If we find your
submitted model has been trained on external data you will receive zero marks for the
At the top of your code, in a block of comments, you must provide a brief answer (one
or two paragraphs) to this Question:
Briefly describe how your program works, and explain any design and training decisions
you made along the way.
Marking Scheme
After submissions have closed, your code wil be run on a holdout test set (i.e. a set of
reviews and ratings that we do not make available to you, but which we will use to test
your model). Marks will be allocated as follows:
12 marks for Algorithms, Style, Comments and Answer to the Question
18 marks based on performance on the (unseen) test set
The performance mark will be a function of the Weighted score, which is:
(1.0 × Correct predictions percentage) + (0.4 × One star away percentage)


本网站支持淘宝 支付宝 微信支付  paypal等等交易。如果不放心可以用淘宝交易!

E-mail: [email protected]  微信:itcsdx