Fun with OpenAI
evilrat
evilrat666 at gmail.com
Mon Dec 19 13:21:26 UTC 2022
On Monday, 19 December 2022 at 08:01:47 UTC, Rumbu wrote:
>
> Question: Split a string in D at each comma without using the
> garbage collector
>
Here is GPT-J-6B output for comparison(I assume ChatGPT using
their biggest model that has 176 Billion params compared to just
6 Billions in this case), I had to adapt it and run several
times, also had to use limit because I was running it on CPU.
One of the variants was simply using split directly in just one
line. Another example had included console output but was quirky.
Sometimes I see how it tries using STL but with D syntax.
Anyway, haven't played that much with GPT-J, but it takes some
trial and error to get something meaningful esp. with smaller GPT
variants.
And running this on the CPU is no fun.
```
0: // A Dlang program that splits a string at each comma without
using the garbage collector
import std.algorithm;
import std.stdio;
void main()
{
string s = "Hello, World";
/// ---- (this part below is generated output) ----
foreach (i; 0.. s.length)
{
if (s[i] == ',')
{
writefln("split string at comma '%s' in line %s",
s.substring(0, i), s.length);
writefln("into: %s", s.substring(0, i));
split(s.substring(i+1).split(','));
}
}
}
```
More information about the Digitalmars-d
mailing list