, ,

[SOLVED] Cs188 project5 p0

$25

File Name: Cs188_project5_p0.zip
File Size: 160.14 KB

Categories: , , Tags: , ,
5/5 - (1 vote)

data is in {‘x’:特å¾, ‘label’:æ ‡ç¾}the form of a dictionary labelbased on featuresthe value to be predicted.
Problem 1 (6 points): Binary Perceptron models.pyThe completed class PerceptronModeland train.pyfunction train_perceptron:
init(self, dimensions): PerceptronModelInitialized weight parameters. The weight variables need to be saved as Parameter()objects with a dimension of 1× dimensions. forward(self, x): Calculates the dot product of the stored weight vector and the given input, returning a tensor object. get_prediction(self, x): Returns 1 if the dot product is non-negative, otherwise returns -1. train_perceptron: Loop through the dataset, update the misclassified samples, and stop training when there is no error in one traversal. Run python autograder.py -q q1the test, -nographicsoptionally without graphics. The autoscorer should complete within 30 seconds when running without graphics correctly.
Neural Network Tips Subsequently, we will implement models such as nonlinear regression, handwritten digit classification, language recognition, and handwritten digit classification with convolutional neural networks.
Create trainable parameters : define the weight matrix Mand bias vector B, the corresponding codes are m = Tensor(2, 1)and b = Tensor(1, 1). Calculate predicted values : Define a linear layer to calculate predicted values predicted_y = self.Linear_Layer(x). Calculate loss : Use the mean squared error loss function mse_lossto calculate the loss loss = mse_loss(predicted_y, y). Training the network : Initialize the optimizer
optim.Adam(self.parameters(), lr=lr). During training, each iteration requires resetting the gradient, calculating the predicted value, calculating the loss, calculating the gradient, and updating the weight. Problem 2 (6 points): Nonlinear regression Complete the class models.pyin RegressionModel, the function train.pyin train_regression, and the function losses.pyin regression_loss:
RegressionModel.init: Complete necessary initialization. RegressionModel.forward: Returns a node of size batch_size×1, representing the model prediction. regression_loss: Computes the loss for a given predicted output and target output. train_regression: Train the model with gradient-based updates. A full score is achieved if the model loss average reaches 0.02 or less, and python autograder.py -q q2the test is run.
Question 3 (6 points): Number classification Complete the class models.pyin DigitClassificationModel, the function train.pyin train_digitclassifier, and the function losses.pyin digitclassifier_loss:
DigitClassificationModel.forward(): Returns a node of size batch_size×10, where a higher score indicates a higher probability that the number belongs to a specific category. Use cross_entropyas loss function : Do not use the ReLU activation function in the last linear layer of the network. The model must achieve at least 97% accuracy on the test set to score a point. Run python autograder.py -q q3the test. You can use dataset.get_validation_accuracy()the calculated verification accuracy to help determine when to stop training.
Question 4 (7 points): Language Identification Complete the class models.pyin LanguageIDModel, the function train.pyin train_langaugeid, and the function losses.pyin languageid_loss:
Question 6 (2 points): Attention Mechanism models.pyA working class that implements AttentionBlockthe “Scaled Dot – Product Attention” formula softmaxleft(Mleft( rac{(Q)(K)^{T}}{sqrt{d}_{k}} ight) ight)(V), which involves operations such as matrix multiplication and transposition, and also requires the application of causal masks.
Question 7 (0 points but interesting): Character – GPT Build a small generative model trained on Shakespeare’s play text to generate the next character. You’ll need to gpt_model.pyedit the code in [ 1 ] to implement Transformer_Blockthe class forwardfunctions and GPTclass forwardfunctions. Once the model is trained and running python chargpt.py, you can experiment with adjusting the network size, changing the training text, and so on.
submit Upload the edited Python file to Gradescope. If collaborating with others, only one person should submit
and tag the other to avoid duplicate submissions that could be mistakenly identified as academic misconduct. The staff reference solution takes about 12 minutes to run the full project automatic grader. If the code takes too long to run, check its efficiency.
CS188 Project 5 Machine Learning

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] Cs188 project5 p0[SOLVED] Cs188 project5 p0
$25