Welcome to the site !!
Did the bike sit for a few months before this happened ?? like over winter , etc ? , it could be as simple as old gas , or it could be a ignition break down (coil, CDI , stator) , or even a stuck or out of adjustment float , allowing the bike to run , but after it starts to drain the bowl , especially on rough terrain , that it starts the misfiring or behaving erratically , then when it stalls , and is sitting while your trying to restart it , then the bowl fills and your off again , not saying that is the issue , but its something to check , especially if the bike sat with Ethanol gas in it , and possibly gummed up the float needle causing it to occasionally stick and allow the bowl to drain , then slowly fill the bowl again if its stuck in a partial closed position
These are the first things that come to mind to eliminate , do you have a manual on the bike ?? , this will help in diagnosing , especially with electrical issues should that be the case , and will help with making sure your float is set properly as well