4 – Batches Solution

Hey there, welcome back. So, now, here’s my solution for the get_target function. So the first thing I did is generate our random window R so using random.randint. So, we want to go from one to our window size, but when you actually, like, do randint, it’s not inclusive, so you wouldn’t get, like, if your window size is five, you would actually only get integers from one to four, so you just have to add a plus one here to actually make sure you get Integers from one to five. Then, we want to get like the start index, so that’s just whatever index we’re at minus R. And then you have to do this kind of edge case thing where if index minus R is less than zero, then you want to set that to zero, because you can get something like if index minus is -2, then you’re gonna kind of wrap around from the back of your word list and that’s gonna mess things up. So, then, the stop of our window is index plus R. So now, we have our window, we have like the start and we have the stop. So, to get the target words, we just look from words from start to where we are, index, and then we look – so this is like the words in the history of our text and this is the words in the future of our text. So, we’re looking at the words from index plus one to stop plus one. And then I’m wrapping this in a set because sets just automatically get rid of duplicates. So if we have duplicate words in this window, then it’s just gonna automatically get rid of them and then we’re gonna have our target words. Then we just return this as a list because this is a set, and so we just convert this into a list and return that. All right. See you in the next video.

%d 블로거가 이것을 좋아합니다: