Polyglot book learning

Discussion of anything and everything relating to chess playing software and machines.

Moderator: Ras

Guenther
Posts: 4718
Joined: Wed Oct 01, 2008 6:33 am
Location: Regensburg, Germany
Full name: Guenther Simon

Polyglot book learning

Post by Guenther »

It's the first time I have spent some time on the book learning ability of polyglot.
Just out of curiosity I created a 16 plies book and attached it to a program
with polyglot version 2.03 with learning capability.

It was a bit tedious in the beginning and only after some research I learned that
the option must be listed before the other book options otherwise an unspecific error will occurr:

Code: Select all

1472023581.734 POLYGLOT [PolyGlot] Book="true"
1472023581.734 POLYGLOT [PolyGlot] BookFile="GS8m.bin"
1472023581.734 POLYGLOT [PolyGlot] BookLearn="true"

Code: Select all

1472024070.776 POLYGLOT *LEARN DRAW*
1472024070.776 POLYGLOT write_integer(): fputc(): Bad file descriptor
1472024070.776 POLYGLOT *** QUIT ***
After changing the sequence of the book options the error disappears, but I wonder when I will see
a change of time stamp/size or any difference at all when doing a diff to the original book file?

Code: Select all

1472028119.354 Adapter->GUI: move h4h5
1472028119.354 POLYGLOT MOVE h5
1472028119.354 POLYGLOT THINK -> WAIT
1472028119.374 GUI->Adapter: result 0-1 {Xboard adjudication}
1472028119.374 POLYGLOT GAME END
1472028119.374 POLYGLOT WAIT
1472028119.374 POLYGLOT *LEARN LOSS*
1472028119.384 GUI->Adapter: force
1472028119.384 POLYGLOT WAIT
How will it be written, or better when will it be really written, when e.g. in a match mode?
(I noticed it is protected when I tried to directly do a comparison with a checksum tool - just
copying the current file, while still running in match mode results in no different entries it seems?)

Guenther
User avatar
hgm
Posts: 28517
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Polyglot book learning

Post by hgm »

Indeed, learning must be switched on before the book file is specified, because Polyglot immediately opens the book when it reads the BookFile option, and decides at that point whether the file should be opened read-write or read-only, depending on the BookLearn setting.

Polyglot should write in the book file when a game finishes, adapting the learn counts for all book positions that occurred in the game. This would not change the size of the book file.

I guess that as long as the same engine stays loaded, and the BookFile is not changed Polyglot will keep the book file open, and will only close it when it exits. I am not sure if it would flush all changes to the file after every game. I think it desirable that it does so, but I will check the source.
Guenther
Posts: 4718
Joined: Wed Oct 01, 2008 6:33 am
Location: Regensburg, Germany
Full name: Guenther Simon

Re: Polyglot book learning

Post by Guenther »

hgm wrote:Indeed, learning must be switched on before the book file is specified, because Polyglot immediately opens the book when it reads the BookFile option, and decides at that point whether the file should be opened read-write or read-only, depending on the BookLearn setting.

Polyglot should write in the book file when a game finishes, adapting the learn counts for all book positions that occurred in the game. This would not change the size of the book file.

I guess that as long as the same engine stays loaded, and the BookFile is not changed Polyglot will keep the book file open, and will only close it when it exits. I am not sure if it would flush all changes to the file after every game. I think it desirable that it does so, but I will check the source.
Thanks for the info. After the match was completed the file was changed!
I don't know though what was changed. Is there some way to extract
the changed info into something readable?
IIRC there once was a tool to make the content of a polyglot book readable?
Guenther
Posts: 4718
Joined: Wed Oct 01, 2008 6:33 am
Location: Regensburg, Germany
Full name: Guenther Simon

Re: Polyglot book learning

Post by Guenther »

Well, because I am still curious what happens with learning in a polyglot book
and my hex editor was not able to show me any differences in the 2 book
files (original and updated - only 20 games learned though!), I did some
research about binary diff tools and found a nice tool which also works
under WIN. It's called VBinDiff and I downloaded it here:

https://www.cjmweb.net/vbindiff/

(Despite not being updated since 2008 and not documented for Win7
it worked out of the box under Win7 64 Ultimate - handles files up to 4GB
and is very fast.)

The comparison now showed me that some values were actually changed
from zero to other values in two columns.

Then I found out (again) that Polyglot can dump the info in the book
for White and Black seperately into plain txt.
You'll get something like that below (excerpt):

Code: Select all

Dump of "GS8mX.bin" for white.
1: 1. e4{46%} b6 2. d4{100%} Bb7 3. Bd3{100%} e6 4. Nf3{100%} c5 5. c3{100%} d6 6. O-O{100%} Nd7 7. Bg5{100%} Qc7 8. Nbd2{100%} 
2: 1. e4{46%} b6 2. d4{100%} Bb7 3. Bd3{100%} e6 4. Nf3{100%} c5 5. c3{100%} d6 6. O-O{100%} Be7 7. Qe2{100%} Nf6 8. e5{100%} 
3: 1. e4{46%} b6 2. d4{100%} Bb7 3. Bd3{100%} e6 4. Nf3{100%} Ne7 5. c4{100%} g6 6. Nc3{100%} Bg7 7. Be3{100%} d6 8. d5{100%} 
4: 1. e4{46%} c6 2. d4{90%} d5 3. e5{39%} c5 4. dxc5{98%} e6 5. Nf3{56%} Bxc5 6. Bd3{100%} b6 7. c3{100%} a5 8. Na3{100%} 
5: 1. e4{46%} c6 2. d4{90%} d5 3. e5{39%} c5 4. dxc5{98%} e6 5. Nf3{56%} Bxc5 6. Bd3{100%} Nc6 7. O-O{100%} f6 8. Qe2{100%} 
6: 1. e4{46%} c6 2. d4{90%} d5 3. e5{39%} c5 4. dxc5{98%} e6 5. Nf3{56%} Bxc5 6. Bd3{100%} Nc6 7. O-O{100%} Nge7 8. Bf4{44%} 
7: 1. e4{46%} c6 2. d4{90%} d5 3. e5{39%} c5 4. dxc5{98%} e6 5. Nf3{56%} Bxc5 6. Bd3{100%} Nc6 7. O-O{100%} Nge7 8. Nbd2{33%} 
8: 1. e4{46%} c6 2. d4{90%} d5 3. e5{39%} c5 4. dxc5{98%} e6 5. Nf3{56%} Bxc5 6. Bd3{100%} Nc6 7. O-O{100%} Nge7 8. a3{22%} 
9: 1. e4{46%} c6 2. d4{90%} d5 3. e5{39%} c5 4. dxc5{98%} e6 5. Nf3{56%} Bxc5 6. Bd3{100%} Ne7 7. O-O{100%} Nbc6 {trans: line=6, ply=14}
...
I did this for both colors in the 2 book files and I thought now being ascii, I should
easily see a difference in the stats, but they are still identical.

I guess the reason is that it needs much more games until a visible effect
appears, even in a quite small book. Is this a correct assumption?
User avatar
hgm
Posts: 28517
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Polyglot book learning

Post by hgm »

I am not familiar with this Polyglot function for dumping books, but I suspect that the numbers shown are just the book weights (converted to a percentage on the basis of weights of all moves from a position). And that it does noy show the learn info at all. In Polyglot books each move has a 16-byte entry, containing an 8-byte position key, a 2-byte move, a 2-byte weight, a 2-byte learn games count and a 2-byte learn half-point count. Only the latter two are changed during learning.

In the WinBoard Edit Book dialog the learn fields are displayed behind the move in braces {}, if they are not bot zero. You should be able to see the effect of learning by stepping through a game that was just learned, with the Edit Book window open and the book installed as GUI book.
Guenther
Posts: 4718
Joined: Wed Oct 01, 2008 6:33 am
Location: Regensburg, Germany
Full name: Guenther Simon

Re: Polyglot book learning

Post by Guenther »

hgm wrote:I am not familiar with this Polyglot function for dumping books, but I suspect that the numbers shown are just the book weights (converted to a percentage on the basis of weights of all moves from a position). And that it does noy show the learn info at all. In Polyglot books each move has a 16-byte entry, containing an 8-byte position key, a 2-byte move, a 2-byte weight, a 2-byte learn games count and a 2-byte learn half-point count. Only the latter two are changed during learning.

In the WinBoard Edit Book dialog the learn fields are displayed behind the move in braces {}, if they are not bot zero. You should be able to see the effect of learning by stepping through a game that was just learned, with the Edit Book window open and the book installed as GUI book.
Well, you are right I can see that info in the brackets in the WB book editor. (Scid doesn't show this and also the level of precision for showing the percentage is a magnitude lower)
46.1% 5151 c7c5 {0/2}
30.1% 3358 e7e5 {3/3}
10.1% 1127 e7e6
8.9% 995 c7c6 {2/2}
2.8% 309 d7d6
1.1% 119 g8f6
1.0% 114 d7d5
My problem is that the stats are not changed though. It seems I had the wrong (?) understanding that the percentage of playing a move would change AND be shown too. Am I wrong here?
If I am wrong here we cannot know what will happen after the learn info is added?

E.g. from the learn info above the learning for the tested program showed 2 losses with Black after 1. e4 c5 and I can confirm from the pgn file that this is true.
How is that info used now, if the percentage remains unchanged and how do we know the consequences, or what this exactly means from reading the learn info?
It looks like Black had 3 more 1. e4 games and played no 1... c5 anymore, but I have no idea if this was by accident or a learning effect...
User avatar
hgm
Posts: 28517
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Polyglot book learning

Post by hgm »

WinBoard does not use the learn info, and the percentages are the playing probabilities WinBoard would assign when the bookis used as a GUI book. The philosophy was that a GUI book is for all engines, and that learn info is specific for one engine. The Edit Book window only shows the learn counts for completeness, and to allow editing them.

When Polyglot uses the book and BookLearn is on, it multiplies the weights ofeach move by a factor derived from the number of plays and points scored with it. I would have to look upexactly how. The idea was that when the number of plays is high the score percentage should be the dominating factor, while for very low number of plays (where the score is not really significant yet) the number of plays should be the dominant factor, in a way that encourages diversity.