Skip to content

Commit

Permalink
minor update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongkaifu committed Dec 1, 2023
1 parent ab5d708 commit ce3f1d1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 34 deletions.
30 changes: 13 additions & 17 deletions Seq2SeqSharp/Corpus/MonoCorpus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,23 +226,19 @@ public List<Dictionary<string, long>> CountTokenFreqs()

public long GetNextLength(Dictionary<long, long> len2counts, long totalRecordsNum)
{
long[] keys = len2counts.Keys.ToArray();
int rndIdx = rnd.Next(keys.Length);
return keys[rndIdx];

//long rndItems = rnd.NextInt64(totalRecordsNum);
//long totalItems = 0;
//foreach (var pair in len2counts)
//{
// long length = pair.Value;
// if (totalItems <= rndItems && totalItems + length >= rndItems)
// {
// return pair.Key;
// }
// totalItems += length;
//}

//return -1;
long rndItems = rnd.NextInt64(totalRecordsNum);
long totalItems = 0;
foreach (var pair in len2counts)
{
long length = pair.Value;
if (totalItems <= rndItems && totalItems + length >= rndItems)
{
return pair.Key;
}
totalItems += length;
}

return -1;
}

public void PrepareDataSet()
Expand Down
30 changes: 13 additions & 17 deletions Seq2SeqSharp/Corpus/ParallelCorpus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,23 +315,19 @@ public interface ICorpus<out T> : IEnumerable<T>

public long GetNextLength(Dictionary<long, long> len2counts, long totalRecordsNum)
{
long[] keys = len2counts.Keys.ToArray();
int rndIdx = rnd.Next(keys.Length);
return keys[rndIdx];

//long rndItems = rnd.NextInt64(totalRecordsNum);
//long totalItems = 0;
//foreach (var pair in len2counts)
//{
// long length = pair.Value;
// if (totalItems <= rndItems && totalItems + length >= rndItems)
// {
// return pair.Key;
// }
// totalItems += length;
//}

//return -1;
long rndItems = rnd.NextInt64(totalRecordsNum);
long totalItems = 0;
foreach (var pair in len2counts)
{
long length = pair.Value;
if (totalItems <= rndItems && totalItems + length >= rndItems)
{
return pair.Key;
}
totalItems += length;
}

return -1;
}

public void PrepareDataSet()
Expand Down

0 comments on commit ce3f1d1

Please sign in to comment.