Discussion on Character Prediction Model in Python

Character Prediction Model in Python
Please see the attached PDF for the assignment requirements. I have also attached the previous homework zip file.

 

Don't use plagiarized sources. Get Your Custom Essay on
Discussion on Character Prediction Model in Python
Just from $10/Page
Order Essay

starter code In this homework, you will work with character-level language models. These models take as input a sequence of characters and predict the next character. You will first implement functionalities for an abstract language model, then build a new Temporal Convolutional Network (TCN).
Starter code and dataset You will train your model on Barrack Obama speeches (we tried other presidents, but Obama has the most publicly available transcribed speeches). For this assignment, we use a simplified character set: 26 lowercase characters (a to z), space and period. A character language model (LanguageModel in models.py) generates text by predicting the 28 value (log- )probability distribution of the next character given a string s (in the function LanguageModel.predict_next). For most models predicting the next log-probability for all characters (LanguageModel.predict_all) is as efficient as predicting the log-probability of the last character only. This is why in this assignment, you will only implement the predict_all function, and compute predict_next from predict_all. The predict_all takes a string s of length n as an input. It predicts the log-probability of the next character for each substring of s[:i] for $i \in {0, \ldots, n}$, including the emtpy string ” and the full string s. The function returns n+1 values. To get you started, we implemented a simple Bigram model, see here for more information. The starter code further contains an AdjacentLanguageModel that favors characters that are adjacent in the alphabet. Use both models to debug your code. Finally, utils.py provides some useful functionality. First, it loads the dataset in SpeechDataset, and it implements a one_hot encoding function that converts a string s into a one-hot encoding of size (28, len(s)). You can create a dataset of one-hot encodings by calling SpeechDataset(‘data/train.txt’, transform=one_hot). This might be useful later during training. You can implement different parts of this homework independently. Feel free to skip parts that seem too hard. However, it might be easiest to follow the order of the assignment.
Log likelihoods of text (10 pts) We start by implementing a log_likelihood function in language.py. This function takes a string as input and returns the log probability of that string under the current language model. Test your implementation using the Bigram or AdjacentLanguageModel.
python3 -m homework.language -m Bigram
Hint: Remember that the language model can take an empty string as input
Hint: Recall that LanguageModel.predict_all returns the log probabilities of the next characters for all substrings.
Hint: The log-likelihood is the sum of all individual likelihoods, not the average You can grade your log-likelihood using:
python3 -m grader homework -v
Relevant Operations
• LanguageModel.predict_all
• utils.one_hot
• and all previous
Generating text (10 pts) Next, implement the sample_random function. This function takes a language model and samples from it using random sampling. You can generate a random sample by randomly generating the next character according to its distribution. The sample terminates if max_len characters are produced, or a period . is generated. Hint: torch.distributions contains many useful sampling functions. Again, test your implementation using the Bigram and grade:
python3 -m grader homework -v Here is what the master solution (TCN) produces:
some of a backnown my but or the understand thats why weve hardships not around work since there one
they will be begin with consider daughters some as more a new but jig go atkeeral westedly.
yet the world.
and when a letter prides.
in the step of support information and rall higher capacity training fighting and defered melined an
Relevant Operations
• torch.distributions
• and all previous
Beam search (20 pts) Implement the function beam_search to generate the top sentences generated by your language mode. You should generate character-by-character and use beam search to efficiently store the top candidate substrings at each step. At every step of beam search expand all possible characters. Terminate a sentence if a period . is generated or max_length was reached. Beam search returns the top n_results either based on their overall log-likelihood or the average per-character log-likelihood average_log_likelihood=True. The percharacter log-likelihood will encourage longer sentences, while the overall log-likelihood ofter terminates after a few words.
Hint: You mind find TopNHeap useful to keep the top beam_size beams or n_results around. Here is a snipped from the master solution TCN with average_log_likelihood=False
thats.
today.
in.
now. And here with average_log_likelihood=True
and we will continue to make sure that we will continue to the united states of american.
and we will continue to make sure that we will continue to the united states of the united states.
and we will continue to make sure that we will continue to the united states of america.
and thats why were going to make sure that will continue to the united states of america. Grade your beam search:
python3 -m grader homework -v
Relevant Operations
• and all previous
TCN Model (20 pts) Your TCN model will use a CausalConv1dBlock. This block combines causal 1D convolution with a nonlinearity (e.g. ReLU). The main TCN then stacks multiple dilated CausalConv1dBlock’s to build a complete model. Use a 1×1 convolution to produce the output. TCN.predict_all should use TCN.forward to compute the log-probability from a single sentence.
Hint: Make sure TCN.forward uses batches of data.
Hint: Make sure TCN.predict_all returns log-probabilities, not logits.
Hint: Store the distribution of the first character as a parameter of the model torch.nn.Parameter
Hint: Try to keep your model manageable and small. The master solution trains in 15 min on a GPU.
Hint: Try a residual block. Grade your TCN model:
python3 -m grader homework -v
Relevant Operations
• torch.nn.Parameter
• torch.nn.functional.log_softmax
• torch.nn.ConstantPad1d
• and all previous
TCN Training (40 pts) Train your TCN in train.py. You may reuse much of the code from prior homework. Save your model using save_model, and test it:
python3 -m grader homework -v Hint: SGD might work better to train the model, but you might need a high learning rate (e.g. 0.1).
Grading You can test your code using
python3 -m grader homework -v In this homework, it is quite easy to cheat the validation grader. We have a much harder to cheat hidden test grader, that is likely going to catch any attempts at fooling it. The point distributions between validation and test will be the same, but we will use additional test cases. Second, in this homework, it is a little bit harder to overfit, especially if you keep your model small enough. However, still, keep in mind that we evaluate your model on the test set. The performance on the test grader may vary. Try not to overfit to the validation set too much. We set the testing log-likelihood threshold such that a Bigram with a log-likelihood of -2.3 gets 0 points and a TCN with log-likelihood -1.3 get the full score. Grading is linear.
Grading The test grader we provide
python3 -m grader homework -v will run a subset of test cases we use during the actual testing. The point distributions will be the same, but we will use additional test cases. More importantly, we evaluate your model on the test set. The performance on the test grader may vary. Try not to overfit to the validation set too much.
Submission (ID is 3849) Once you finished the assignment, create a submission bundle using
python3 bundle.py homework [YOUR ID] and submit the zip file online. Please note that the maximum file size our grader accepts is 20MB. Please keep your model compact. Please double-check that your zip file was properly created, by grading it again
python3 -m grader [YOUR ID].zip
Online grader We will use an automated grader online to grade all your submissions. There is a limit of 5 submissions per assignment. The online grading system will use a slightly modified version of python and the grader:
• Please do not use the exit or sys.exit command, it will likely lead to a crash in the grader
• Please do not try to access, read, or write files outside the ones specified in the assignment. This again will lead to a crash. File writing is disabled.
• Network access is disabled. Please do not try to communicate with the outside world.
• Forking is not allowed!
• print or sys.stdout.write statements from your code are ignored and not returned.
Running your assignment on google colab You might need a GPU to train your models. You can get a free one on google colab. We provide you with an ipython notebook that can get you started on colab for each homework. If you’ve never used colab before, go through colab notebook (tutorial) When you’re comfortable with the workflow, feel free to use colab notebook (shortened) Follow the instructions below to use it.
• Go to http://colab.research.google.com/.
• Sign in to your Google account.
• Select the upload tab then select the .ipynb file.
• Follow the instructions on the homework notebook to upload code and data.

 

Get professional assignment help cheaply

Are you busy and do not have time to handle your assignment? Are you scared that your paper will not make the grade? Do you have responsibilities that may hinder you from turning in your assignment on time? Are you tired and can barely handle your assignment? Are your grades inconsistent?

Whichever your reason may is, it is valid! You can get professional academic help from our service at affordable rates. We have a team of professional academic writers who can handle all your assignments.

Our essay writers are graduates with diplomas, bachelor, masters, Ph.D., and doctorate degrees in various subjects. The minimum requirement to be an essay writer with our essay writing service is to have a college diploma. When assigning your order, we match the paper subject with the area of specialization of the writer.

Why choose our academic writing service?

  • Plagiarism free papers
  • Timely delivery
  • Any deadline
  • Skilled, Experienced Native English Writers
  • Subject-relevant academic writer
  • Adherence to paper instructions
  • Ability to tackle bulk assignments
  • Reasonable prices
  • 24/7 Customer Support
  • Get superb grades consistently

 

 

 

 

 

 

Order a unique copy of this paper
(550 words)

Approximate price: $22

Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

We value our customers and so we ensure that what we do is 100% original..
With us you are guaranteed of quality work done by our qualified experts.Your information and everything that you do with us is kept completely confidential.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

The Product ordered is guaranteed to be original. Orders are checked by the most advanced anti-plagiarism software in the market to assure that the Product is 100% original. The Company has a zero tolerance policy for plagiarism.

Read more

Free-revision policy

The Free Revision policy is a courtesy service that the Company provides to help ensure Customer’s total satisfaction with the completed Order. To receive free revision the Company requires that the Customer provide the request within fourteen (14) days from the first completion date and within a period of thirty (30) days for dissertations.

Read more

Privacy policy

The Company is committed to protect the privacy of the Customer and it will never resell or share any of Customer’s personal information, including credit card data, with any third party. All the online transactions are processed through the secure and reliable online payment systems.

Read more

Fair-cooperation guarantee

By placing an order with us, you agree to the service we provide. We will endear to do all that it takes to deliver a comprehensive paper as per your requirements. We also count on your cooperation to ensure that we deliver on this mandate.

Read more

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Open chat
1
You can contact our live agent via WhatsApp! Via +1 817 953 0426

Feel free to ask questions, clarifications, or discounts available when placing an order.

Order your essay today and save 20% with the discount code VICTORY