what's going on everybody and welcome to
part 4 of the ml in halite three
tutorials where we left off we were
creating for real hopefully this time
some training data I'm gonna be pretty
angry if this is not correct but we
checked it last time and I think I'm all
set
anyways what I've got here is actually
over 50,000 files and it was 50
gigabytes of training data I think we're
all set so I'm gonna go ahead and stop
all of these from running and we'll
close these and we'll pop into here come
into training data and let's sort by
size make sure looks like they're all
between a thousand and 400 1006 I want
to make sure none of them are just like
empty and then we can also sort by the
name looks like the largest is just
under 5500 but pretty quickly I mean we
only have a handful of 1000 halite games
like where where the AI somehow
collected over a thousand which is
pretty impressive because we're called
we're only making one ship so that
starts us at 5,000 one ship goes down to
4,000 and we set this threshold to save
as just basically 4,100 so did that ship
collect any howlite now what we want to
do is find out where should we draw the
line so so for example let's come into
oops this is just the data I don't
really care about that let's go oh we're
okay so I am I guess we could take
testing grounds I think we'll just
modify testing grounds there's a couple
of things I want to check so the first
thing would be let's do import OS and
then all files equals OS lister training
data don't forget to put this in quotes
and what I'd like to do
import matplotlib dot pie plot as PLT
and what i want to do actually this
machine probably does even have map plot
lip so let's go ahead and grab that let
me make sure pip is to the python that
we're using hurry up
okay pip pip install matt lot lib so a
grab matplotlib hmm
make sure we can we should be good
though i just want to make sure no
errors and what i'd like to do is plot
like a distribution of the scores kind
of for two reasons one is I'm just
curious right now but also what we could
do is keep this exact same threshold and
then after we've trained a model we can
see is the distribution exactly the same
as in like almost like what's the
average score of the games you also
could do an average but or both I'm
curious to know after we train a model
how much better did is our new model so
coming back over here all files OS tout
Lister train data let's just print Len
all files run that really quick let's
see how quickly we can get through that
pretty pretty darn fast
so then for F because if we use file I
think that's a I thought file was a
keyword anyway I'm gonna keep with f4f
in all files so that should be the file
name so then we just want to say how I
highlight amount equals F dot split well
split by the dash and then we'll go with
the zero with element so if we print how
I amount will just break after the first
one brick we can see 40 100 so then I'll
just do how I amounts here
then we will delete to here halite
amounts and amount
let's do print Lynn highlight underscore
amounts also just so I can dev this to
start let's just do like 500 cool okay
so now we want to plot a histogram
I believe it's PLT dot pissed in
matplotlib and then for a histogram you
just have to pass X's so we want to pass
highlight amounts and then it's like
bins it might be H bins or n bins we're
gonna find out in a second I'm gonna say
5 and then PLT dot show run that oh it
worked ok so it's only 40 100 because as
we iterate I think we're just going in
an order so let's do let's do 15 I hate
to do let's do 1500 first just see ok so
we can see clearly the most common is
4,100 then it kind of goes down let's do
them all I think I think that's looking
pretty darn pretty darn good yeah I'm
actually not sure why that was so
difficult why would that be so
challenging for it because we said we
only wanted so many bins so why is the
displace of challenging for it
it's curious what have I done wrong I
feel like it didn't actually put them in
the bins right uh like pull it up real
quick I don't know what I've done wrong
here let's do a map plot Lib histogram
pie plot hist
that's correct see if we say you know
five bins it really should only have
like five you know categories have been
uh four clearly it wanted to label like
a bajillion could you please not take
five years to load and just I don't know
load any of them these are all a
matplotlib Torg about this one this
isn't matplotlib oh yeah
there we go yeah how come how come their
bins look normal num bins X numbers
how come miner is so ugly bins equals
five just to make sure bins is the key
word it looks like that person passed
and it's still gonna be a pain isn't it
weird I don't know what I've done I
thought with the bins it would just show
it would be like the range almost but
that doesn't appear to be the case
yeah we've got like all these million
tick marks someone comment below what
I've done wrong it's kind of a bummer
I'll keep these around they'll keep the
script the other thing we could do is I
think it's from is it statistics that
has the mean operation from Statistics
imp or mean for now I'm just gonna
comment this out I guess because I don't
think that's really working print mean
halite amounts what what's wrong oh dude
okay so I bet I know what I've done
wrong up here let's see so right now
these are not uh this needs to be an
integer because right now it's a string
let's see if that fixed it whoa man what
a dumb mistake okay okay so so this sort
of helps I probably cut it off at about
the 10,000 mark just to see what the
real distribution is but yeah as you can
see it's a pretty significant or even
maybe 2,000 mark or something but you
can see we got very few of these games
then it ticks up real fast okay cool so
then the other thing we really could do
now is this and we get the mean which is
4202 so that's the average so later
after we train a model we can come back
and see what is the new mean okay so so
now that we've done that I'm going what
I'm gonna do is I'm gonna come in here
training data old this is from before so
over time I'll probably keep at least
the previous training data set obviously
it's 50 gigabytes at some point we can't
be doing that and soon we're gonna have
multiple ships and we're just gonna have
you know huge data sets so we can't keep
too many of them
normally I probably won't have you know
50,000 games though that's a lot of
games so so really we would just raise
the threshold probably but for now I
want I do want to see if we can improve
the mean game from one training example
so testing grounds instead of calling
that testing grounds now what I'd like
to call it I'm not sure why I had to
save it let me just test it real quick
here cool what we're gonna call this
instead now we're gonna just copy paste
I don't know why do we have another test
oh this is the output okay coming back
over here I'm gonna get rid of test
because just taking up space also sent a
bot to I think we only needed that
protesting as well I'm gonna delete that
this I'm gonna say let's call this
training data
destroy distribution cool okay so now
let me just copy and paste either of
these and we'll call this a sent a train
I don't know anyway basically it's gonna
train we'll use this to be our training
script okay so to train I'm gonna use
tensorflow you could also use straight
Karos I'm going to use care us from
tensorflow
but you can do whatever you want if you
don't know much about Karros and
tensorflow and all that you can always
go to Python programming it finally it
knows that one over you could type in
Quiroz and then come down here and learn
all about it cool okay
so wow we still can't get to mat plot
this has been happening for like years
we're like I just can't access
matplotlib org sometimes I really wish
they would figure out what the heck's
going on there anyway I think we're done
there we'll open up a browser if we need
it later
so anyways let's get started import
tensorflow as T I hate that sublime does
that to me import tensorflow as TF we're
going to use OS we're gonna pry use
numpy as NP we're going to import time
we are going to probably need random we
need random to like shuffle to my
knowledge there is no shuffle for
secrets you can modify secrets to an
extent to have a shuffle but that's not
really the point of the secrets modules
so they don't have one we're also gonna
from T qdm import TQ DM which I don't
have T qdm so let's go ahead and pip
install TQ DM this just gives us a nice
progress bar as you're doing things and
so we have so many files as we iterate
it would be nice to know where are we in
this freaking process okay now from
tensor and in fact
I'm not sure I can do this any faster
than I can write it but I might be able
to so it's got a Python program at net
let's go back to that kara series cuz
you always just need like the same
freaking imports so let's go down to how
to use your trained model optimizing
models maybe let's view part three here
so convolutional neural networks let's
see what the imports art of the
statement dang who did these awesome
freaking pictures yeah basically all of
this these like sequential dense dropout
activation flattened comms 2d max
pooling 2d we need all that and I don't
really see any point in typing all that
out pretty sure this is faster okay so
the only other thing that we want is
gonna be from tensorflow dot Kara's dot
callbacks we want to import tensor board
this is so we can display the beautiful
beautiful graphs as we go okay so I
think we're ready so now as we build out
this model we have a few things that we
need to do we we basically the data set
is too big to load into memory first of
all we can chunk it down probably and
actually load the entire set onto a GPU
at least in the kit in the setting that
it's in right now but I know if
anybody's following along and you don't
have say a 24 gigabyte GPU or a 12 or
whatever and you can't fit in in memory
it's important that we batch it in now I
know
caris has some sort of generator and you
can load it in and I've done stuff with
that before but then when I need to
start customizing stuff that's where it
starts getting unbelievably complicated
so I just don't do it that way if you
want to use the generator and post how
you would do it go for it
I just find it adds undue complexity to
a problem and like in this case I'm just
trying to do like testing here I'm not
trying to spend five days figuring out
how I can create a custom generator that
loads batches of files so anyway not
going to do it but yeah if you want to
do it go for it have fun so the first
I'm gonna say is load trained files and
I'm gonna set that to be false so
basically true if we already have a
batch train files I guess I'll call this
train files this will make a little more
sense when we get there but basically we
are going to take these files because
keep in mind these are only one megabyte
right the training data so we're gonna
want to load you know all right fifty a
hundred two hundred you could load quite
a few even like a thousand of these and
it's no big deal probably depending on
what size your memory is so but over
time the games are gonna get much much
bigger because right now we're only
going for 50 turns and we only have one
ship now imagine later on we've got 500
turns so it's already 10 megabytes and
then imagine you've got 10 ships
well that's 100 megabytes right there
per game so so eventually it's going to
be even more important that we we batch
these files so that's what I'm just
gonna do that from the very beginning so
for now it'll be false but and then also
like if you're gonna train for more than
one Epoque or you want to train and then
tinker some things and train again this
is what we can do is as we load and kind
of combine everything and do the
balancing and all that stuff we only
really need to do that one time so it
would be useful to save it when we're
done cuz that's gonna take probably
longer than the training is going to
take at least for a small model so then
we're also gonna load meant to keep the
caps on load pre evil again I'm gonna
set to false but true if you want to
transfer learn from existing model okay
something like that I have to fix these
ok so now the final thing is over time
like right now I just have a halite
threshold so for example we could say
you know halite threshold and initially
it was 4,100 over time we might want to
change that so I'm gonna leave that for
now and we'll come back to that that
number because again we're probably
changing that to something a little more
dynamic as well so then also we need a
training chunk size and for now I think
we can set that to be even a hundred is
pretty good probably a hundred or even
maybe 200 that'll be 200 megabytes more
than you know totally easy to fit on to
just about any GPU no problem
we might even want it that larger I'm
gonna go with 500 okay so then if you
have one pre-assign what I wanted I want
to prove model name for now I'm just
gonna leave that empty because we don't
we don't actually have one then let's
think I guess we would want a validation
game count we'll set that to be like how
many games do we want to use for
validation I think I'll say 50 that
means like 10% of each training chunk
would be a validation 50 might be a
little large but I'll go with 50 that's
fine okay
so then we'll choose a name for this
model so how are we gonna save it blah
blah blah I'm gonna say this I'm gonna
call it phase 1 - and then for now let's
just throw in int time dot time so
that'll be the name of the model and
then finally epochs let's just do one
Epoque I don't really see any reason why
we need to do a bunch then training data
derp equals training data fix this D
cool okay so now what we want to do is
iterate over our our training data
and basically we first need to get all
of the files so training data names or
training let's call this training file
names and for now that'll be an empty
list
are we ready iOS that's not where you
want to import it for F and actually
let's just hope was it in here for F in
OS dot lister so I don't really want to
copy that exact thing sent a train
let's do for F n OS dot list der
training data
Durer then what we want to say is
basically the we'll say the let's say
how I equals and then that split this
so we'll say halide amount equals that
split and then we'll ask the question if
halite amount is greater than or equal
to the high light threshold that we set
if that's the case then what we want to
do is say training file names we want to
dot append OS dot path to join the
training data Durer and that file name
so f okay now print let's just say after
the threshold we have Len training file
names files and actually we should call
this games okay so run that again make
sure all that works kind of surprised
how long that's taking don't expect that
to take very long okay so we have all
the games so what if we um
so clearly 4100 we don't need 52,000
games especially for this first step so
what if we said 4500 because we did see
how few games we had after the so 1455
so we want a little more that like my
targets about 2,000 so let's try 4400
Wow so how about 44 feet okay I think
we'll go with mmm
it's hard to say forty I don't know if
it would be better to have the extra
games I'll go I'll go with 4400 just so
we have plenty of games to learn from I
think that makes the most sense okay so
with 30 to 35 games that gives us a
little over 150,000 samples to learn
from of course most of those are just
random and worthless but hopefully some
of them will be somewhat decent and that
after 50 only 50 turns most of the moves
or at least a large number of those
moves were actually probably pretty
useful if we were able to gain 400
halite from it with only one ship I
think that's okay so so at this point we
would want a random shuffle those
training foundings as you can as you saw
before they go in perfect order I'm not
really sure we want to do that so random
not shuffle training file names okay and
then at this point I think what I want
to do is probably stop it here because
the next point is really for us to
balance and then train the data and I
think if I'm gonna do that I probably
should split this off because the
balance is definitely gonna take a
considerable amount of code the model
shouldn't take too much in fact we could
probably copy and paste again from a
Kaos page and be good there yeah I think
the bount for the balance I'm gonna
split that away so anyways I'm gonna
stop it here and in the next tutorial
what we'll do is we basically you want
to get to the point where you balance
now this data probably is already pretty
well balanced because it was a random
choice and a pretty good random cuz we
use secret choice so actually for the
for this step for the first step we
actually probably don't need to shuffle
the data or I'm sorry balance the data
because there's probably there is
probably an equal amount of like go up
and left and right and down and don't
move there's probably an equal amount of
those because it was just randomly
selected for there might be a slight
weight towards different things like for
example I think in how I you know you
might depending on you know if the ship
went left or right like if most of the
halite was you know over in one
direction you know me you have way more
turns or steps in that direction also
probably still like hold still may be
one of the actually the more common
moves because you're like waiting on a
plot of how light I don't really know
anyway regardless we have to balance at
some point so might as well just throw
in the code
do that now so yeah that's what we'll do
in the next tutorial so if you've got
questions comments concerns whatever
feel free to leave them below yeah
otherwise I will see you guys in the
next video where we balance create the
model and hopefully start the training
process and it shouldn't maybe in that
training process I'll just pause it
while it trains it shouldn't take too
too long to train especially with only
this many games but we'll see
anyways see you next video