text:
plot.survfit {survival} R Documentation

## Plot method for survfit objects

### Description

A plot of survival curves is produced, one curve for each strata. The log=T option does extra work to avoid log(0), and to try to create a pleasing result. If there are zeros, they are plotted by default at 0.8 times the smallest non-zero value on the curve(s).

Curves are plotted in the same order as they are listed by print (which gives a 1 line summary of each). This will be the order in which col, lty, etc are used.

### Usage

## S3 method for class 'survfit'
plot(x, conf.int=, mark.time=FALSE,
pch=3, col=1, lty=1, lwd=1, cex=1, log=FALSE, xscale=1, yscale=1,
xlim, ylim, xmax, fun,
xlab="", ylab="", xaxs="r",  conf.times, conf.cap=.005,
conf.offset=.012,
conf.type = c("log", "log-log", "plain", "logit", "arcsin"),
mark, noplot="(s0)", cumhaz=FALSE,
firstx, ymin, ...)

### Arguments

 x an object of class survfit, usually returned by the survfit function. conf.int determines whether pointwise confidence intervals will be plotted. The default is to do so if there is only 1 curve, i.e., no strata, using 95% confidence intervals Alternatively, this can be a numeric value giving the desired confidence level. mark.time controls the labeling of the curves. If set to FALSE, no labeling is done. If TRUE, then curves are marked at each censoring time. If mark is a numeric vector then curves are marked at the specified time points. pch vector of characters which will be used to label the curves. The points help file contains examples of the possible marks. A single string such as "abcd" is treated as a vector c("a", "b", "c", "d"). The vector is reused cyclically if it is shorter than the number of curves. If it is present this implies mark.time = TRUE. col a vector of integers specifying colors for each curve. The default value is 1. lty a vector of integers specifying line types for each curve. The default value is 1. lwd a vector of numeric values for line widths. The default value is 1. cex a numeric value specifying the size of the marks. This is not treated as a vector; all marks have the same size. log a logical value, if TRUE the y axis wll be on a log scale. Alternately, one of the standard character strings "x", "y", or "xy" can be given to specific logarithmic horizontal and/or vertical axes. xscale a numeric value used like yscale for labels on the x axis. A value of 365.25 will give labels in years instead of the original days. yscale a numeric value used to multiply the labels on the y axis. A value of 100, for instance, would be used to give a percent scale. Only the labels are changed, not the actual plot coordinates, so that adding a curve with "lines(surv.exp(...))", say, will perform as it did without the yscale argument. xlim, ylim optional limits for the plotting region. xmax the maximum horizontal plot coordinate. This can be used to shrink the range of a plot. It shortens the curve before plotting it, so that unlike using the xlim graphical parameter, warning messages about out of bounds points are not generated. fun an arbitrary function defining a transformation of the survival (or probability in state, or cumulative hazard) curves. For example fun=log is an alternative way to draw a log-survival curve (but with the axis labeled with log(S) values), and fun=sqrt would generate a curve on square root scale. Four often used transformations can be specified with a character argument instead: "S" gives the usual survival curve, "log" is the same as using the log=T option, "event" or "F" plots the empirical CDF F(t)= 1-S(t) (f(y) = 1-y), and "cloglog" creates a complimentary log-log survival plot (f(y) = log(-log(y)) along with log scale for the x-axis). The terms "identity" and "surv" are allowed as synonyms for type="S". The argument "cumhaz" causes the cumulative hazard function to be plotted. xlab label given to the x-axis. ylab label given to the y-axis. xaxs either "S" for a survival curve or a standard x axis style as listed in par; "r" (regular) is the R default. Survival curves have historically been displayed with the curve touching the y-axis, but not touching the bounding box of the plot on the other 3 sides, Type "S" accomplishes this by manipulating the plot range and then using the "i" style internally. The "S" style is becoming increasingly less common, however. conf.times optional vector of times at which to place a confidence bar on the curve(s). If present, these will be used instead of confidence bands. conf.cap width of the horizontal cap on top of the confidence bars; only used if conf.times is used. A value of 1 is the width of the plot region. conf.offset the offset for confidence bars, when there are multiple curves on the plot. A value of 1 is the width of the plot region. If this is a single number then each curve's bars are offset by this amount from the prior curve's bars, if it is a vector the values are used directly. conf.type One of "plain", "log" (the default), "log-log" or "logit". Only enough of the string to uniquely identify it is necessary. The first option causes confidence intervals not to be generated. The second causes the standard intervals curve +- k *se(curve), where k is determined from conf.int. The log option calculates intervals based on the cumulative hazard or log(survival). The log-log option bases the intervals on the log hazard or log(-log(survival)), and the logit option on log(survival/(1-survival)). mark a historical alias for pch noplot for multi-state models, curves with this label will not be plotted. (Also see the istate0 argument in survcheck.) cumhaz plot the cumulative hazard rather than the probability in state or survival. Optionally, this can be a numeric vector specifying which columns of the cumhaz component to plot. ymin this will normally be given as part of the ylim argument firstx this will normally be given as part of the xlim argument. ... other arguments that will be passed forward to the underlying plot method, such as xlab or ylab.

### Details

If the object contains a cumulative hazard curve, then fun='cumhaz' will plot that curve, otherwise it will plot -log(S) as an approximation. Theoretically, S = \exp(-\Lambda) where S is the survival and \Lambda is the cumulative hazard. The same relationship holds for estimates of S and \Lambda only in special cases, but the approximation is often close.

When the survfit function creates a multi-state survival curve the resulting object also has class ‘survfitms’. Competing risk curves are a common case. In this situation the fun argument is ignored.

When the conf.times argument is used, the confidence bars are offset by conf.offset units to avoid overlap. The bar on each curve are the confidence interval for the time point at which the bar is drawn, i.e., different time points for each curve. If curves are steep at that point, the visual impact can sometimes substantially differ for positive and negative values of conf.offset.

### Value

a list with components x and y, containing the coordinates of the last point on each of the curves (but not the confidence limits). This may be useful for labeling.

### Note

In prior versions the behavior of xscale and yscale differed: the first changed the scale both for the plot and for all subsequent actions such as adding a legend, whereas yscale affected only the axis label. This was normalized in version 2-36.4, and both parameters now only affect the labeling.

In versions prior to approximately 2.36 a survfit object did not contain the cumulative hazard as a separate result, and the use of fun="cumhaz" would plot the approximation -log(surv) to the cumulative hazard. When cumulative hazards were added to the object, the cumhaz=TRUE argument to the plotting function was added. In version 2.3-8 the use of fun="cumhaz" became a synonym for cumhaz=TRUE.

points.survfit, lines.survfit, par, survfit

### Examples

leukemia.surv <- survfit(Surv(time, status) ~ x, data = aml)
plot(leukemia.surv, lty = 2:3)
legend(100, .9, c("Maintenance", "No Maintenance"), lty = 2:3)
title("Kaplan-Meier Curves\nfor AML Maintenance Study")
lsurv2 <- survfit(Surv(time, status) ~ x, aml, type='fleming')
plot(lsurv2, lty=2:3, fun="cumhaz",
xlab="Months", ylab="Cumulative Hazard")

[Package survival version 3.5-5 Index]


text:
# Remove all occurrences of an element from an array, in place

I solved this problem:

Given an array nums and a value val, remove all instances of that value in-place and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. The order of elements can be changed. It doesn't matter what you leave beyond the new length.

How can I improve its execution time and also, if there is any better way of doing it?

public int removeElement(int[] numbers, int value) {
int index = 0;
for(; index < numbers.length; index++) {
if(numbers[index] == value) {
boolean otherNumberPresent = false;
int j = index + 1;
for(; j < numbers.length; j++ ){
if(numbers[j] != value) {
otherNumberPresent = true;
break;
}
}
if(otherNumberPresent) {
int temp = numbers[j];
numbers[j] = numbers[index];
numbers[index] = temp;
} else {
return index;
}
}
}
return index;
}

A much simpler solution is to have an "input pointer" i and an "output pointer" o.

public int removeElement(int[] numbers, int value) {
int o = 0;
for (int i = 0; i < numbers.length; i++) {
if (numbers[i] != value) {
numbers[o++] = numbers[i];
}
}
return o;
}

The fundamental issue with your code is that it has two loops in it. As a rule of thumb, that suggests it is a quadratic algorithm: if you double the size of the input, the runtime could be four times worse.

In practice that should (depending on the input profile) happen rarely, so long as the array doesn't have the first half full of the target number and the second full of other stuff. But even with a more random distribution, this will be slower than needed because it keeps dumping the values to remove back into the bit of the array it is about to search!

The answer by 200_success works well enough, but also has a higher than necessary cost because it writes something in almost every step of the loop.

There is another solution, hinted at in the question with the order doesn't matter clause: when you need to delete something, move the replacement from the end. Because the end is discarded anyway, you don't even need to swap out the old value with the one you want to delete.

Although it is dangerous to predict without profiling, that will probably prove a more efficient approach. The heuristic is that most steps in the loop will just be a read and equality comparison before moving on to the next step. (This should also be friendly to a bunch of low level details such as the cache coherence and branch predictor, but that is very detailed and really needs profiling.)

format: plain


text:
# Advice on Full Time Community College Math Instructor Position

I have to do a teaching demo on the following:

Please treat the committee as students in your Calculus II class. Please take 12-15 minutes to introduce your lesson on the Taylor Series and its applications. Take the final two minutes to indicate how you would finish your lesson for the day

Here's my plan:

1. Begin by stating that a Taylor Series is an expansion of a function into an infinite sum of terms.

2. Present the Taylor expansion for $$\cos x=1-x^2/2!+x^4/4!+...$$ as an example

3. Use Desmos (a computer will be provided) to show how the more sequence of terms that we have, the better the approximation of the $$\cos x$$ graph. Example:

The red line is the cos x graph and the blue line is the approximation.

1. Talk quickly about why the formula works (getting $$c_0, c_1, c_2$$) using $$f(x) = c_0 + c_1(x-a) + c_2(x-a)^2 + c_3(x-a)^3+...$$ to obtain $$f(x) = f(a) + f'(a)/1! (x-a) + f''(a)/2!(x-a)^2 + f'''(a)/3!(x-a)^3 + ...$$

2. Use this formula to obtain the Taylor series expansion of $$cos x$$

3. Have a student centered formative assessment last 2-3 minutes and find the Taylor expansion for sin x

My only concern is: Is this too much for a 12-15 minute demo?

• To me, this looks like more than 15 minutes worth, but you may be faster than I, or think about things differently than I. Honestly, the best way to determine if you can do the demo in 12-15 minutes is to get in front of a white board or projector and actually do the demo... Nov 3 '18 at 22:27
• Yes, such things always take longer in real life than in practice sessions. Nov 4 '18 at 13:23
• I agree with the comments made saying this is likely too long. However, 15 minutes is long enough to share and explain a Taylor series expansion. I would spend time motivating its importance to approximation in science etc. The idea that $\sin x = x$ if $x$ is small enough. Why $=$ is wrong, but rather there is some error. Oh, an error which your students can understand since they already covered the alt. series estimation theorem most likely. See supermath.info/OldschoolCalculusII.pdf around page 204 for some pictures that visualize error and local vs. global. Nov 4 '18 at 13:45
• This could work, but keep in mind that students might not see $\sin x$ as a familiar friend, especially if their trig. background is terrible. Also, they might not see why we'd want these seemingly more complicated expressions for something that seems simpler. Another possibility is to start with the geometric series sum $\frac{a}{1-r}$ as a way of expanding $\frac{1}{1-x}$ and looking at the corresponding graphs. But if geometric series is something relatively foreign to them, then this might not work very well. (continued) Nov 5 '18 at 10:29
• All answers seem to lack the "its applications" part. Nov 5 '18 at 11:55

Your intuition is correct that this is far too much for a 12-15 minute lesson. The committee knows that there is no way you could deliver a whole lesson, even an introductory one, on this topic.

Since you've only got 15 minutes, plan to use it to spark interest in the topic, knowing that you're only showing the committee the very beginning.

For example, why not show students the cosine function on a small interval around $$x=0$$, and ask them what polynomial it reminds them of? "Does it look like some kind of $$x^2$$ or $$x^3$$?" Let them decide which one, and then graph their guess on top of $$y=\cos(x)$$. You will have the opportunity to discuss the vertical intercept and the width of the graph – that it can be adjusted (by multiplying a term by a constant). In this way, your lesson could start as a game about building the cosine function from simpler functions, and students will be involved in the guessing process. I see this occupying up to 5 minutes. Then do your steps 1 and 2, and you're probably out of time.

In my opinion, using your lesson time to draw on your students' previous experience with trig and power functions helps them see that they are already capable of doing much of the intuitive work leading to Taylor polynomials, and it validates that this new thing is something that doesn't have to seem like just applying another magic math formula.

You should definitely plan to tell the committee what else the lesson would include (if you had the time), but I also would tell them what they should already know. [e.g. "Hey, class...let's remember back when we studied graphs of power functions. Do you all remember how to draw the graph of $$y=-x^2$$?"]

Have a student centered formative assessment last 2-3 minutes and find the Taylor expansion for sin x

You could considerably simplify this assessment (for an introduction) by asking them what just the first term of the series expansion should be. If you took the time to remind them of the "long-run behavior" of a polynomial when you discussed the cosine function, you could let them use their calculators to determine what the 2nd term of the series expansion of $$\sin(x)$$ is.

• Say I wanted to start with sin x on a window of [-.75,.75]. This obviously looks like the line y=x. How could I draw on my students' previous experience to get to the -x^3 term? Nov 4 '18 at 1:49
• Zoom out to [-2.5, 2.5] and notice that the function curves back toward the x-axis. Since Taylor polynomials "locally" resemble their parent functions (as opposed to Fourier series, which bear "global" resemblance), you could ask what kind ("degree") of polynomial would bend like this? Of course, the end behavior is different, but close-in, they should say some kind of negative cubic. Here is an opportunity to discuss that what you're trying to do is find a polynomial that looks like sin(x) when you're pretty close to x = 0. Nov 4 '18 at 2:08
• Just know that I'm kind of spitballing here, so my idea isn't a well-formed plan -- it's just a thought as to how one might give a start-of-class teaser for this topic. Nov 4 '18 at 2:10
• Also, your students (should) probably know about turning points of a polynomial at this point, so you have more leverage for asking them to make an educated guess about the next term. Nov 4 '18 at 2:11
• No this is great because we're conceptualizing taylor series as a function that can actually be written as a sum of a lot of terms using graphical representations. This actually helps with retention IMO Nov 4 '18 at 2:26

Caveat: I'm just a random Internet poster, not an instructor, so take this with a grain of salt. And get some advice from blooded veterans.

A. It's too much. 1 and 2 are plenty for 12 minutes.

B. Write out the entire 50 minute lecture, practice it at once, and write up a synthesis of the last 35 minutes. I suggest something like topic, time, key points, perhaps purpose (you can draw a 4 column table and fill it out in the 3 minute). Make it simple enough so that you can actually explain it in 2 minutes. Test yourself to see that you can (it is simple enough summary).

C. Your beginning should have some intro that is a little more motivational, less dry (1 is too theoretical). Maybe something like "sins and cosines are complicated and polynomials are easy so we like to change them into something easier to work with" Or "you will need this in physics" or whatever the practical rationale is for why this is in the curriculum (not too real analysis-y, please). [I do quite like 2, though.]

D. Remember that your target audience at a juco is not math superstars. They are a lower skill set than you or even than an AP calculus class. Good people who want to get through this to support their chem/physics class or nursing degree or what have you. They are looking to progress and get jobs or to transfer to lower level state schools (and then get jobs). Have some sympathy for this and for them (without being obvious or patronizing about it either).

E. I suspect the interview committee wants to see that you can manage time, organize your thoughts, are practiced, command the room, have some energy, etc. And can get through the topic without getting too tied up into every nuance. I think you have plenty of math chops and that will not be their main worry (that you know the topic well). Sure review the standard lesson and be absolutely up to speed on it (especially if they probe...but if they don't, don't feel a need to flaunt.). But the objective is probably 20% math skill (and mostly about being above a skill threshold rather than how high above it). 80% is instructional ability...which is very, very strongly correlated to planning the lecture and practicing it at least 3 times. [Don't bother with that level of time investment when doing the job, except for first lecture, but definitely for the interview.]

F. Do a little reconnaissance and figure out what text they use. See how it addresses this topic and work the homework problems in that text.

G. Really this whole topic is a little bit of a pain for the student and not the most important material. Maybe even why they picked it. Show you can get the kids through the damned thing.

• Several good points. However, regarding G, I suspect this topic lends itself well to good use (and not good use) of technology, giving good (and not so good) applications, relating to earlier stuff vs. not relating to earlier stuff (i.e. linear approximations in Calculus 1), easy to get too caught up in (as you put it) "every nuance" involving rigorous convergence issues, etc. Nov 5 '18 at 13:09
• +1 A, B, C, E (especially E) are extremely insightful and useful for OP. Nov 5 '18 at 16:15
• What does «juco» mean? Mar 3 at 9:36

I'd take an entirely different approach, though the faculty that is assessing you may not view it favorably.

Mathematicians tend to view the logic of math as intrinsically beautiful.

The vast majority of people do not. The vast majority considers math to be hoop jumping and weirdly arbitrary rules that must be followed to get check marks. They have no idea why anyone would care about formulae.

Simply telling students "Taylor Series are important!" does not motivate them. Glossing over it or lecturing them for a few minutes on it will also fail to motivate them.

To begin addressing this, I would use intellectual need to motivate the students.

For example, in lower levels of math, one might teach fractions as part of a whole or something like that, or sections of circles, or naming amount of food. Or, you could make them feel intellectual need by having them how they'd share 5 pieces of licorice among 3 kids and name the amount each kid got.

One could teach exponents as repeated multiplication then do a bunch of notational drills. Or, you could make students feel the need for exponents by teaching them about the spread of infectious diseases. "If 3 people are infected initially and each sick person infects one more person each week, what will happen in 6 months?" Then, you make a table, and let them struggle for a while to figure out that in week, say, 10, they calculate the number of infections by going $$3\times2\times2\times2\times2\times2\times2\times2\times2\times2\times2$$, which is just a pain to read and write.

In the eyes of most mathematicians, the average person, including college students, have shockingly little interest in the logic of math because they just want to get answers and check marks. So, what will you do to make them feel the need for a Taylor Series?

Check out the work on "Intellectual Need" in math education.

The risk: The "Curse of Knowledge" unfortunately, implies a very high probability that the people assessing you assume that students will intuitively understand that Taylor Series are interesting and important, and thus just need to be told so. Experts, very frequently, are shocked to find out that basic concepts, such as why anyone cares about Taylor Series, completely fly over the head of students who ace quizzes and tests on Taylor Series.

• Regarding your last paragraph, this is an important point to keep in mind when teaching. However, my guess is that at a community college the hiring committee will be VERY familiar (and even very cognizant) with what is appropriate for their students. Nov 5 '18 at 13:14
• In case my "and even very cognizant" part misses the mark, my intent was to say that not only will the hiring committee know this , they will likely be actively thinking about it during the presentation. Nov 5 '18 at 13:29
• Perhaps the community college you're familiar with is different from the one near my home! The one near my home produces many students who regularly say "The teacher went so fast so I just scribbled everything down on paper as fast as I could, and man, my hand is tired! But I can't make sense of my notes and I have no idea what the class was about." Then the assessments are almost entirely procedural. :( I'd still say that, given 12-15 minutes, if the original poster can get the students to care at all about Taylor Series, that would be a big accomplishment. Nov 8 '18 at 6:01
• Procedural knowledge is nothing to be sniffed at. I expect there are many students that fall short of that. Baby steps... Nov 8 '18 at 19:31
• When I say the tests - and thus thinking - are almost entirely procedural, I mean that students can get an A+ in the courses by doing a lot of polynomial long division calculations correctly, while still regularly confusing $2\div3$ and $3\div2$. That's how weak their conceptual understanding is. Nov 8 '18 at 21:08


text:
46 views

There are $6$ boxes numbered $1,2$,$\dots$,$6$. Each box is to be filled up either with a red or a green ball in such a way that at least $1$ box contains a green ball and the boxes containing green balls are consecutively numbered. The total number of ways in which this can be done is :

1. $5$
2. $21$
3. $33$
4. $60$
in Others
edited | 46 views

Option B. 21

If only one of the boxes has a green ball, it can be any of the 6 boxes. So, we have 6 possibilities.
If two of the boxes have green balls and then there are 5 consecutive sets of 2 boxes. 12, 23, 34, 45, 56.
If 3 of the boxes have green balls, there are 4 possibilities: 123, 234, 345, 456.
If 4 boxes have green balls, there are 3 possibilities: 1234, 2345, 3456.
If 5 boxes have green balls, there are 2 possibilities: 12345, 23456.
If all 6 boxes have green balls, there is just 1 possibility.

Total number of possibilities = 6 + 5 + 4 + 3 + 2 + 1 = 21.

by (134 points) 2 7


text:
Warning: This document is for an old version of Rasa Core. The latest version is 0.8.6.

# Interactive Learning¶

Note

This is the place to start if you have a great idea for a bot but you don’t have any conversations to use as training data. We will assume that you’ve already thought of what intents and entities you need (check out the Rasa NLU docs if you don’t know what those are).

Example Code on GitHub

## Motivation: Why Interactive Learning?¶

There are some complications to chatbot training which makes them more tricky than most machine learning problems.

The first is that there are several ways of getting to the same goal, and they may all be equivalently good. Therefore it is wrong to say with certainty that given X, you should do Y, and if you do not do exactly Y then you are wrong. This is essentially what you do in a fully supervised learning case. We want the bot to be able to learn it can get to a successful state through a number of different means.

Secondly, the utterances from users will be strongly affected by the actions of the bot. That means that a network trained on pre-collected data will suffer from exposure bias, this is when a system is trained to make predictions but is never given the ability to train on its own predictions, instead being given the ground truth every time. This has been shown to have issues when trying to predict sequences multiple steps into the future.

Also, from a practical perspective Rasa Core developers should be able to train via the Wizard of Oz method. I.e. if you want a bot to do a certain task, you can simply pretend to be a bot for a little while and at the end it will learn how to respond. This is a good way of learning how to make natural and flowing

## The Bot¶

We will build a bot that can recommend concerts to go to. We’ll show how to implement context-aware behaviour without writing a flow chart. For example, if our user asks the question: which of those has better reviews?, our bot should know whether they want to compare musicians or venues.

Let’s go!

## The Domain¶

We will keep the concert domain simple, and won’t add any slots just yet. We’ll also only support these intents: "greet", "thankyou", "goodbye", "search_concerts", "search_venues", "compare_reviews" Here is the domain definition:

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 slots: concerts: type: list venues: type: list intents: - greet - thankyou - goodbye - search_concerts - search_venues - compare_reviews entities: - name templates: utter_greet: - "hey there!" utter_goodbye: - "goodbye :(" utter_default: - "default message" utter_youarewelcome: - "you're very welcome" actions: - utter_default - utter_greet - utter_goodbye - utter_youarewelcome - actions.ActionSearchConcerts - actions.ActionSearchVenues - actions.ActionShowConcertReviews - actions.ActionShowVenueReviews

## Stateless Stories¶

We start by training a stateless model on some simple dialogues in the Rasa story format.

Below is an excerpt of the stories.

In many cases, your bot’s ‘conversations’ are just a single turn and response: “Hello” is always met with a greeting, “goodbye!” is always met with a sign-off, and the correct response to “thank you” is pretty much always “you’re welcome”.

Notice that below, we’ve defined two stories, showing that action_show_venue_reviews and action_show_concert_reviews are both possible responses to the compare_reviews intent, but neither references any context. That comes later.

## greet
* _greet
- action_greet

## happy
* _thankyou
- action_youarewelcome
...

## compare_reviews_venues
* _compare_reviews
- action_show_venue_reviews

## compare_reviews_concerts
* _compare_reviews
- action_show_concert_reviews

## Training¶

We start by training the policy to recognise these input-output pairs independently of any context. ( You can see the definition of the ConcertPolicy class in policy.py. ) Run the script train_init.py. This creates a training set of conversations by randomly combining the stories we’ve provided into longer dialogues, and then trains the policy on that dataset.

Then, run the script run.py to talk to the bot. You should be able to have a conversation similar to the one below

Note

we haven’t connected an NLU tool here, so when you type messages to the bot you have to type the intent starting with a _. If you want to use Rasa NLU / wit.ai / Lex you can just swap the Interpreter class in run.py.

Bot loaded. Type hello and press enter :
_greet
hey there!
_search_concerts
Here's what I found:
Katy Perry, Foo Fighters
_goodbye
goodbye :(

Now we’ll train the bot to use context to respond correctly to the compare_reviews intent.

## Interactive Learning¶

Run the script train_online.py. This first repeats the process in the train_init script, creating a stateless policy.

It then runs the bot so that you can provide feedback to train it:

Happy paths

We can start talking to the bot as before, directly entering the intents. For example, if we type _greet, we get the following prompt:

_greet
------
Chat history:

bot did:        action_listen

user said:      _greet

whose intent is:     greet

we currently have slots: {'location': None}

------
The bot wants to [greet] due to the intent. Is this correct?

1.       Yes
2.       No, intent is right but the action is wrong
3.       The intent is wrong

This gives you all the info you should hopefully need to decide what the bot should have done. In this case, the bot chose the right action (‘greet’), so we type 1 and hit enter. We continue this loop until the bot chooses the wrong action.

Providing feedback on errors

We’ve just asked the bot to search for concerts, and now we’re asking it to compare reviews. The bot happens to choose the wrong one out of the two possibilities we wrote in the stories:

_compare_reviews
------
Chat history:

bot did:        action_search_concerts

bot did:        action_suggest

bot did:        action_listen

user said:      _compare_reviews

whose intent is:     compare_reviews

we currently have slots: {'location': None}

------
The bot wants to [show_venue_reviews] due to the intent. Is this correct?

1.       Yes
2.       No, intent is right but the action is wrong
3.       The intent is wrong

Now we type 2, because it chose the wrong action, and we get a new prompt asking for the correct one. This also shows the probabilities the model has assigned to each of the actions.

------
what is the next action for the bot?

0       default  0.00148131744936
1       greet    0.0970264300704
2       goodbye  0.0288009047508
3       listen   0.00123148341663
6       search_cinemas  0.000627864559647
8       search_films    0.0367559418082
9       suggest         0.0261212754995
11      youarewelcome   0.594935178757
13      explain_options 0.0516758263111
14      store_slot      0.00145904591773
15      show_cinema_reviews     0.00887114647776
16      show_film_reviews       0.0870243906975

In this case, the bot should show_film_reviews (rather than cinema reviews!) so we type 16 and hit enter.

Note

The policy model will get updated on-the-fly, so that it’s less likely to make the same mistake again. You can also export all of the conversations you have with the bot so you can add these as training stories in the future.

Now we can keep talking to the bot for as long as we like to create a longer conversation. At any point you can type _export and the bot will write the current conversation to a file, which you can then add as a training example for the future.