Answered step by step
Verified Expert Solution
Question
1 Approved Answer
data science/coding question: Part A (1 point) Consider the following grammar beginning with the start symbol S and with the rules S phrase-token phrase-token phrase-token
data science/coding question:
Part A (1 point) Consider the following grammar beginning with the start symbol S and with the rules S phrase-token phrase-token phrase-token tic toc l tic toc What is the set of sentences that is generated by this grammar? Express the "language" generated by this grammar as succinctly as possible. Your answer should be in the same kind of form as our description of the sentences generated by the "nearly" grammar described above, which was (nearly)'finished YOUR ANSWER HERE Part B (1 point) In this problem, you are going to generate random sentences from a grammar. To generate random sentences, you'll need to use a random function from the np.random module In [4]: np.random.rand? This function returns a value that is uniformly distributed between and 1 In [ : np.random.rand () For an example of how to use random numbers in generating random sentences from a grammar, see the adjective phrase function defined above Edit the function tic to generate random sentences from the grammar defined in Part A. In [ def tic(): Generates random sentences using the grammar in Part A. Your answer should include a single space after each tic" and 'toc". Hint: your solution can be done in 5 lines of code (or less), including the return statement. Returns a string representing a sentence from the grammar in Part A # YOUR CODE HERE raise NotImplementedError () Part A (1 point) Consider the following grammar beginning with the start symbol S and with the rules S phrase-token phrase-token phrase-token tic toc l tic toc What is the set of sentences that is generated by this grammar? Express the "language" generated by this grammar as succinctly as possible. Your answer should be in the same kind of form as our description of the sentences generated by the "nearly" grammar described above, which was (nearly)'finished YOUR ANSWER HERE Part B (1 point) In this problem, you are going to generate random sentences from a grammar. To generate random sentences, you'll need to use a random function from the np.random module In [4]: np.random.rand? This function returns a value that is uniformly distributed between and 1 In [ : np.random.rand () For an example of how to use random numbers in generating random sentences from a grammar, see the adjective phrase function defined above Edit the function tic to generate random sentences from the grammar defined in Part A. In [ def tic(): Generates random sentences using the grammar in Part A. Your answer should include a single space after each tic" and 'toc". Hint: your solution can be done in 5 lines of code (or less), including the return statement. Returns a string representing a sentence from the grammar in Part A # YOUR CODE HERE raise NotImplementedError ()Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started