|
#include <stdio.h> |
|
#include <stdint.h> |
|
#include <stdlib.h> |
|
|
|
int main(void) { |
|
FILE *fp = fopen("word2vec.bin","rb"); |
|
struct { |
|
uint32_t items; |
|
uint32_t dim; |
|
} hdr; |
|
|
|
fread(&hdr,sizeof(hdr),1,fp); |
|
printf("%u items of size %u\n", hdr.items, hdr.dim); |
|
|
|
float *v = malloc(sizeof(float)*hdr.dim); |
|
for (int j = 0; j < 10; j++) { |
|
uint16_t wlen; |
|
fread(&wlen,sizeof(wlen),1,fp); |
|
char *word = malloc(wlen+1); |
|
fread(word,wlen,1,fp); |
|
word[wlen] = 0; |
|
fread(v,hdr.dim*sizeof(float),1,fp); |
|
|
|
printf("\"%s\" -> %f, %f, %f, ...\n",word,v[0],v[1],v[2]); |
|
free(word); |
|
} |
|
free(v); |
|
fclose(fp); |
|
} |
|
|