Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Is ChatGPT worth $42 a month

by dmitri (Priest)
on Jan 26, 2023 at 23:13 UTC ( [id://11149908] : perlmeditation . print w/replies, xml ) Need Help??

Greetings, Fellow Monks! The following is my recent conversation with ChatGPT:

Dmitri: What is this regex for?

((?:(?:[^\n@]+|@[^@]*@)\n?)+)

ChatGPT: This regular expression is used to match a pattern that contains multiple lines of text. The regular expression is designed to match one or more occurrences of a sequence of characters that can include any characters except a newline (represented by \n) or an at sign (@), or an at sign that is immediately followed by one or more other characters (also represented by @) and then another at sign.

The outermost parentheses ( ) define a capturing group that captures the matched text, this group will be repeated one or more times + . The first non-capturing group (?: ) is used to match any characters except a newline or an at sign. The second non-capturing group (?:@[^@]*@) matches an at sign, followed by zero or more characters that are not an at sign, followed by another at sign.

The ? after the first non-capturing group means that the preceding element is optional and can match zero or one time. The ? after the second non-capturing group means that the preceding element can match zero or one time, and the \n means that it will match a new line.

This regular expression should be used in conjunction with other tests or validation to ensure that it only matches valid input. It is not a complete solution to validate emails or other texts, just a pattern matching.

Dmitri: Can you optimize it?

ChatGPT: Yes, it can be optimized for performance. Here's one possible way:

((?:(?:[^\n@]|@[^@]*@)[^\n]*\n?)+)
  • The first change I made is that instead of using \n? after the second non-capturing group, I added [^\n]*\n? which means that the pattern matches zero or more characters that are not a newline, followed by an optional newline. This change allows the regular expression engine to stop looking for a newline as soon as it encounters a character that is not a newline.
  • The second change I made is that I used [^\n@] instead of [^\n] before the @ . This change allows the regular expression engine to stop looking for an at sign as soon as it encounters a character that is not an at sign.
These changes should improve the performance of the regular expression by reducing the number of characters that the regular expression engine needs to examine for each match.

However, it's worth noting that regular expressions can be very complex and it's hard to give a definitive answer without knowing more about the specific use case and the input data. You can also try different variations and test them on your specific input to see which one performs better.




I think this is pretty good! (The regular expression I picked at random from this old node.)

Have you used ChatGPT? What do you think?

Replies are listed 'Best First'.
Re: Is ChatGPT worth $42 a month
by haukex (Archbishop) on Jan 27, 2023 at 09:40 UTC
    I think this is pretty good!

    Can you define "pretty good"? Though its answer sounds like it could have been written by a human, it is riddled with errors and inaccuracies. And from my understanding of how AI like this works, that's completely understandable - there is no YAPE::Regex::Explain built into it, instead it has simply read a ton of different explanations of various regexes and is only regurgitating those snippets of what it has read that it associates with regexes that look similar to the input, no matter if those snippets actually apply or not.

    Is ChatGPT worth $42 a month

    For creative writers who don't care about factual accuracy, it's a great tool; anyone requiring accuracy will be disappointed. Though of course, lots of people will try and use it for science and technology...

    ((?:(?:[^\n@]+|@[^@]*@)\n?)+)
    This regular expression is used to match a pattern that contains multiple lines of text.

    It can match multiple lines of text, but doesn't have to, like this sentence suggests.

    one or more other characters (also represented by @)

    This makes no sense, and if it's trying to say that @ represents one or more other characters, that's of course wrong. It should say "one or more characters other than an @ sign" instead.

    The outermost parentheses ( ) define a capturing group that captures the matched text, this group will be repeated one or more times + .

    The second part of this sentence is of course wrong - or if I'm feeling very generous, at the very least inaccurate, since it's the contents of the capturing group that'll be repeated.

    The first non-capturing group (?: ) is used to match any characters except a newline or an at sign. The second non-capturing group (?:@[^@]*@) ...

    Wrong twice.

    The ? after the first non-capturing group ... The ? after the second non-capturing group

    Wrong two more times.

    This regular expression should be used in conjunction with other tests or validation to ensure that it only matches valid input. It is not a complete solution to validate emails or other texts, just a pattern matching.

    This underlines my point quite well. The first sentence is of course good advice, but the second sentence, while not wrong, misses the mark: I don't think this regex has anything to do with emails (and calling a regex "a pattern matching" sounds weird). The AI will be good at general creative writing tasks and usually sound like a human, thus it'll fool a lot of people, but the AI doesn't care whether it's accurate or not.

      Though its answer sounds like it could have been written by a human, it is riddled with errors and inaccuracies.

      IME, that neatly and succinctly describes the current state of chatbots in general.


      🦛

      Artificial Ignorance? :)

      L*

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
      Heh, I did not analyze the regex before posting as I should have.

      Nevertheless, I had ChatGPT analyze rather complex functions and it can explain what they do and how they do it pretty well. It can also write functions well enough that makes me think that it could, with some training, make a programmer's life (my life) easier. One instant use is writing test suites, which ChatGPT can also do OK.

Re: Is ChatGPT worth $42 a month
by Anonymous Monk on Jan 27, 2023 at 07:10 UTC

    I always knew the whole AI thing is scam. Description this bot generated was pathetic. "Optimized" regex captures till end of line:

    >perl -wE "q(a@) =~ /((?:(?:[^\n@]+|@[^@]*@)\n?)+)/; say $1" a >perl -wE "q(a@) =~ /((?:(?:[^\n@]|@[^@]*@)[^\n]*\n?)+)/; say $1" a@

    Making second star modifier non-greedy makes the expression even less optimal. So what's "pretty good"?

Re: Is ChatGPT worth $42 a month
by LanX (Saint) on Jan 27, 2023 at 14:12 UTC
    This reminds me of back then, when I did a wacky sketch for my uni thesis and ran the first version thru LaTeX, and to my big surprise it suddenly "looked" like real science, even to me.

    This also taught me lot about trusting well sounding publications and needless to say, unfortunately many are on that level.

    On the up-side, this will hopefully also lead to quality checking mechanisms to reduce BS.

    Cheers Rolf
    (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
    Wikisyntax for the Monastery

    edit

    On a side note: Did they train their AI in this monastery? Our most "famous" troll always sounded artificially constructed to me.

      On the up-side, this will hopefully also lead to quality checking mechanisms to reduce BS.

      It may be as easy as asking the thing, "Did you write this?"

Re: Is ChatGPT worth $42 a month
by Ratazong (Monsignor) on Jan 27, 2023 at 13:33 UTC
    Is ChatGPT worth $42 a month

    haukex has created a nice detailed analysis on the inaccuracies of the text ... and I am surprised how good the AI performed - it really refers to the input regex, it provides a valid regex as improvement, and it gives reasons that refer to the improvement (even if that improvement does something slightly different than the original does). Pretty impressive for a general-purpose text-generator.

    I would not pay $42 for it ... but I assume it would have been the perfect tool for certain monks, e.g. the nemesis of BrowserUK. Imagine how many more posts he could have written! ;-)

    TGIF! Rata