The base to emitter resistor is required to assure that the transistor switches off when the opto-isolator switches off. It also serves to shunt any leakage current from the opto to common, so that the transistor will be completely off. The value of the resistor needs to be low enough to assure that the combined leakage currents will never bring the base voltage high enough to turn the transistor on at all. It must also allow any stored charge on the base to be quickly drained, so that the transistor switches off quickly.
The value of the resistor needs to be low enough to assure that the combined leakage currents will never bring the base voltage high enough to turn the transistor on at all.
Both Dana and "DAD" are correct. The base is current driven, R3 must allow enough base current for the transistor to saturate, at which time the Vbe will be around 0.7 volts. So to calculate the values of the 2 resistors, you need to start with the collector current required for the relay, then determine the base drive to fully saturate the transistor for that current, and then determine the R3 value to assure that there is adequate drive once the voltage drop in the opto-isolator is known for that current. That is why most designers would first choose a value for R4 that they like, instead of doing the calculations. Some circuits are not as critical as others, unless you would be striving for the absolute minimum power use.